List of usage examples for org.springframework.core.io ByteArrayResource ByteArrayResource
public ByteArrayResource(byte[] byteArray)
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStepTest.java
private HttpEntity<MultiValueMap<String, Object>> createTestAppBitsRequest() throws IOException { HttpEntity<String> resourcesPart = new HttpEntity<String>("[]"); HttpEntity<ByteArrayResource> dataPart = new HttpEntity<>( new ByteArrayResource(Files.readAllBytes(testAppBitsPath)), HttpCommunication.zipHeaders()); MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>(); multiPartRequest.add("resources", resourcesPart); multiPartRequest.add("application", dataPart); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<>(multiPartRequest, headers); }
From source file:be.roots.taconic.pricingguide.service.MailServiceImpl.java
@Override public void sendMail(Contact contact, byte[] pricingGuide) throws MessagingException { final MimeMessageHelper helper = new MimeMessageHelper(javaMailSender.createMimeMessage(), true); helper.setFrom(fromEmail);/*from www . jav a 2s. c om*/ if (StringUtils.isEmpty(testEmail)) { helper.setTo(contact.getEmail()); } else { helper.setTo(testEmail.split(",")); } if (!StringUtils.isEmpty(bccEmail)) { helper.setBcc(bccEmail.split(",")); } helper.setSubject("Your " + documentTitle); final String body = "Dear " + contact.getFullName() + ",<br>" + "<br>" + "Your " + documentTitle + " is attached.<br>" + "<br>" + "Please <a href=\"http:www.taconic.com/customer-service/contact-us\">contact us</a> for any additional information.<br>" + "<br>" + "Taconic Biosciences, Inc.<br>" + "One Hudson City Centre<br>" + "Hudson, New York 12534<br>" + "North America +1 888 822-6642<br>" + "Europe +45 70 23 04 05<br>" + "info@taconic.com<br>" + "www.taconic.com"; helper.setText(body, true); helper.addAttachment(documentFileName, new ByteArrayResource(pricingGuide)); javaMailSender.send(helper.getMimeMessage()); }
From source file:de.hybris.platform.core.TenantRestartTest.java
@Override @Before/*from w w w .j av a 2 s . c o m*/ public void setUp() throws Exception { final ApplicationContext parent = Registry.getCoreApplicationContext(); applicationContext = new GenericApplicationContext(); applicationContext.setParent(parent); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); xmlReader.loadBeanDefinitions(new ByteArrayResource(MESSAGE_LISTENER_DEF.getBytes())); applicationContext.refresh(); testListener = applicationContext.getBean(TestAfterTenantStartupEventListener.class); Assertions.assertThat(testListener).isInstanceOf(TestAfterTenantStartupEventListener.class); super.setUp(); }
From source file:alfio.manager.system.SmtpMailer.java
@Override public void send(Event event, String to, List<String> cc, String subject, String text, Optional<String> html, Attachment... attachments) {//from w ww . j a v a 2 s . c om MimeMessagePreparator preparator = (mimeMessage) -> { MimeMessageHelper message = html.isPresent() || !ArrayUtils.isEmpty(attachments) ? new MimeMessageHelper(mimeMessage, true, "UTF-8") : new MimeMessageHelper(mimeMessage, "UTF-8"); message.setSubject(subject); message.setFrom( configurationManager.getRequiredValue( Configuration.from(event.getOrganizationId(), event.getId(), SMTP_FROM_EMAIL)), event.getDisplayName()); String replyTo = configurationManager.getStringConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), MAIL_REPLY_TO), ""); if (StringUtils.isNotBlank(replyTo)) { message.setReplyTo(replyTo); } message.setTo(to); if (cc != null && !cc.isEmpty()) { message.setCc(cc.toArray(new String[cc.size()])); } if (html.isPresent()) { message.setText(text, html.get()); } else { message.setText(text, false); } if (attachments != null) { for (Attachment a : attachments) { message.addAttachment(a.getFilename(), new ByteArrayResource(a.getSource()), a.getContentType()); } } message.getMimeMessage().saveChanges(); message.getMimeMessage().removeHeader("Message-ID"); }; toMailSender(event).send(preparator); }
From source file:nl.surfnet.coin.teams.service.impl.GroupServiceBasicAuthentication10aTest.java
@Test public void testGetGroupMembersEntryFaultyJsonResponse() { super.setResponseResource(new ByteArrayResource("not-even-valid-json".getBytes())); GroupMembersEntry groupMembersEntry = groupService.getGroupMembersEntry(provider, "personId", "whatever", 0, 0);/*from w ww . j av a2s . c o m*/ assertTrue(groupMembersEntry.getEntry().isEmpty()); }
From source file:org.cloudfoundry.identity.uaa.config.YamlServletProfileInitializerTests.java
@Test public void testActiveProfiles() throws Exception { System.setProperty("spring.profiles.active", "foo"); Mockito.when(context.getResource(Matchers.anyString())) .thenReturn(new ByteArrayResource("spring_profiles: bar".getBytes())); initializer.initialize(context);/* w ww .j a v a2 s . c om*/ assertEquals("bar", environment.getActiveProfiles()[0]); }
From source file:net.javacrumbs.springws.test.template.FreeMarkerTemplateProcessor.java
public Resource processTemplate(Resource resource, WebServiceMessage message) throws IOException { try {//w ww. ja va 2s. co m Configuration configuration = configurationFactory.createConfiguration(); Map<String, Object> properties = new HashMap<String, Object>(); properties.putAll(WsTestContextHolder.getTestContext().getAttributeMap()); if (message != null) { properties.put("request", getXmlUtil().loadDocument(message)); } properties.put("IGNORE", "${IGNORE}"); StringWriter out = new StringWriter(); configuration.getTemplate(resource.getURL().toString()).process(properties, out); return new ByteArrayResource(out.toString().getBytes("UTF-8")); } catch (TemplateException e) { throw new IllegalStateException("FreeMarker exception", e); } }
From source file:ch.algotrader.dao.AbstractDaoTest.java
@After public void cleanup() throws Exception { if (this.session != null) { this.session.close(); ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("TRUNCATE TABLE GenericItem".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, DATABASE.getDataSource()); TransactionSynchronizationManager.unbindResource(DATABASE.getSessionFactory()); }/*from ww w. java 2 s . c o m*/ }
From source file:com.foilen.smalltools.email.EmailBuilder.java
/** * Include an attachment. Warning, since JavaMail needs a replayable resource, the content of the input stream is first loaded into memory. * * @param attachmentFilename// w ww .j av a 2s. c o m * the filename in the email * @param inputStream * the input stream * @return this */ public EmailBuilder addAttachmentFromStream(String attachmentFilename, InputStream inputStream) { attachments.add(new EmailAttachment(attachmentFilename, new ByteArrayResource(StreamsTools.consumeAsBytes(inputStream)))); return this; }
From source file:com.onedrive.api.resource.support.UploadSession.java
public UploadSession uploadFragment(long startIndex, long endIndex, long totalSize, byte[] data) { Assert.notNull(uploadUrl, "UploadSession instance invalid. The uploadUrl is not defined."); Assert.notNull(data, "The data is required."); MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); headers.add("Content-Range", "bytes " + startIndex + "-" + endIndex + "/" + totalSize); ResponseEntity<UploadSession> response = getOneDrive().getRestTemplate().exchange(uploadUri(), HttpMethod.PUT, new HttpEntity<ByteArrayResource>(new ByteArrayResource(data), headers), UploadSession.class); UploadSession session = response.getBody(); session.setUploadUrl(uploadUrl);/* w ww.j a v a 2 s. c o m*/ session.complete = response.getStatusCode().equals(HttpStatus.CREATED) || response.getStatusCode().equals(HttpStatus.OK); return session; }