List of usage examples for org.springframework.core.io ByteArrayResource ByteArrayResource
public ByteArrayResource(byte[] byteArray)
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Creates a {@link ByteArrayResource} from an input stream * //w w w . j av a 2s . c om * @param is the stream to read from * @return the resource */ @SuppressWarnings("unused") public static ByteArrayResource createResourceFromStream(InputStream is) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b; try { b = new byte[is.available()]; for (int n; (n = is.read(b)) != -1;) { bos.write(b); } } catch (IOException e) { e.printStackTrace(); } return new ByteArrayResource(bos.toByteArray()); }
From source file:org.jboss.fuse.wsdl2rest.util.SpringCamelContextFactory.java
/** * Create a {@link SpringCamelContext} list from the given bytes *//*from ww w. jav a2 s . c o m*/ public static List<SpringCamelContext> createCamelContextList(byte[] bytes, ClassLoader classsLoader) throws Exception { return createCamelContextList(new ByteArrayResource(bytes), classsLoader); }
From source file:org.cloudfoundry.identity.uaa.config.YamlPropertiesFactoryBeanTests.java
@Test public void testLoadResourcesWithOverride() throws Exception { YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); factory.setResources(new Resource[] { new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()), new ByteArrayResource("foo:\n bar: spam".getBytes()) }); Properties properties = factory.getObject(); assertEquals("bar", properties.get("foo")); assertEquals("baz", properties.get("spam.foo")); assertEquals("spam", properties.get("foo.bar")); }
From source file:it.ozimov.springboot.templating.mail.model.impl.EmailAttachmentImpl.java
public ByteArrayResource getInputStream() { return new ByteArrayResource(attachmentData); }
From source file:com.enonic.cms.core.mail.AbstractSendMailService.java
public final void sendMail(AbstractMailTemplate template) { try {//from w w w . ja v a2s .co m MessageSettings settings = new MessageSettings(); setFromSettings(template, settings); settings.setBody(template.getBody()); final MimeMessageHelper message = createMessage(settings, template.isHtml() || !template.getAttachments().isEmpty()); message.setSubject(template.getSubject()); final Map<String, InputStream> attachments = template.getAttachments(); for (final Map.Entry<String, InputStream> attachment : attachments.entrySet()) { message.addAttachment(attachment.getKey(), new ByteArrayResource(IOUtils.toByteArray(attachment.getValue()))); } if (template.isHtml()) { message.setText("[You need html supported mail client to read this email]", template.getBody()); } else { message.setText(template.getBody()); } if (template.getMailRecipients().size() == 0) { this.log.info("No recipients specified, mail not sent."); } for (MailRecipient recipient : template.getMailRecipients()) { if (recipient.getEmail() != null) { final MailRecipientType type = recipient.getType(); switch (type) { case TO_RECIPIENT: message.addTo(recipient.getEmail(), recipient.getName()); break; case BCC_RECIPIENT: message.addBcc(recipient.getEmail(), recipient.getName()); break; case CC_RECIPIENT: message.addCc(recipient.getEmail(), recipient.getName()); break; default: throw new RuntimeException("Unknown recipient type: " + type); } } } sendMessage(message); } catch (Exception e) { this.log.error("Failed to send mail", e); } }
From source file:org.apache.ftpserver.config.spring.SpringConfigTestTemplate.java
protected FtpServer createServer(String config) { String completeConfig = "<server id=\"server\" xmlns=\"http://mina.apache.org/ftpserver/spring/v1\" " + "xmlns:beans=\"http://www.springframework.org/schema/beans\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\" " + "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd " + "http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd " + "\">" + config + "</server>"; XmlBeanFactory factory = new XmlBeanFactory(new ByteArrayResource(completeConfig.getBytes())); return (FtpServer) factory.getBean("server"); }
From source file:org.cloudfoundry.identity.uaa.config.YamlMapFactoryBeanTests.java
@Test public void testGetObject() throws Exception { factory.setResources(new ByteArrayResource[] { new ByteArrayResource("foo: bar".getBytes()) }); assertEquals(1, factory.getObject().size()); }
From source file:com.hillert.botanic.model.Image.java
public Image(String name, byte[] data, Plant plant) { this(name, new ByteArrayResource(data), plant); }
From source file:org.apache.smscserver.test.spring.SpringConfigTestTemplate.java
protected SmscServer createServer(String config) { String completeConfig = "<server id=\"server\" xmlns=\"http://mina.apache.org/smscserver/spring/v1\" " // + "xmlns:beans=\"http://www.springframework.org/schema/beans\" " // + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " // + "xsi:schemaLocation=\" " // + "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd " // + "http://mina.apache.org/smscserver/spring/v1 http://mina.apache.org/smscserver/smscserver-1.0.xsd " // + "\">" // + config + "</server>"; XmlBeanFactory factory = new XmlBeanFactory(new ByteArrayResource(completeConfig.getBytes())); return (SmscServer) factory.getBean("server"); }
From source file:com.w3ma.m3u8web.controller.DownloadPlaylistController.java
@RequestMapping(value = "/playlist", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public ResponseEntity<ByteArrayResource> getPlaylist(final HttpServletResponse response) throws IOException { logger.debug("getPlaylist called"); final HttpHeaders headers = new HttpHeaders(); response.setHeader("Content-Disposition", "attachment; filename=playlist.m3u"); return new ResponseEntity<>( new ByteArrayResource(playlistGeneratorService.getPlaylistByteArrayOutputStream().toByteArray()), headers, HttpStatus.OK);/*from www .ja va2 s . c o m*/ }