本文整理汇总了Java中org.springframework.core.io.InputStreamSource类的典型用法代码示例。如果您正苦于以下问题:Java InputStreamSource类的具体用法?Java InputStreamSource怎么用?Java InputStreamSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InputStreamSource类属于org.springframework.core.io包,在下文中一共展示了InputStreamSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
@Test
public void test() {
InputStreamSource source = new ByteArrayResource(this.expectedText.getBytes(StandardCharsets.UTF_8));
assertThat(source).isNotNull();
PhotoLocationExtraPhotosKeywordCSVParser parser = new PhotoLocationExtraPhotosKeywordCSVParser(source);
assertThat(parser).isNotNull();
Map<String, List<String>> parsedMap = null;
try {
parsedMap = parser.parse();
} catch (IOException e) {
// TODO Auto-generated catch block
fail("exception on parse: "+ e.getMessage());
}
assertThat(parsedMap).isNotNull();
assertThat(parsedMap.size()).isEqualTo(3);
assertThat(parsedMap.keySet()).contains("DSC00305.txt","DSC00498.txt","DSC00520.txt");
List<String> photo1 = parsedMap.get("DSC00305.txt");
assertThat(photo1.size()).isEqualTo(2);
assertThat(photo1.get(0)).isNotNull();
assertThat(photo1.get(0)).isEqualTo(bosque.getName());
assertThat(photo1.get(1)).isNotNull();
assertThat(photo1.get(1)).isEqualTo(montanias.getName());
}
示例2: testKeywordParsing
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
@Test
public void testKeywordParsing() {
String level = "\"\",\"Niveles\",\"Paisaje\"\n\"1\",\"5:20\",\"Colinas,Llano,Veg media,Veg escasa\"";
InputStreamSource source =new ByteArrayResource(level.getBytes(StandardCharsets.UTF_8));
PhotoLocationLandscapeLevelsCSVParser parser = new PhotoLocationLandscapeLevelsCSVParser(source);
try {
List<String> keywords = parser.parseKeywords();
assertThat(keywords).isNotNull();
assertThat(keywords.size()).isEqualTo(4);
} catch (IOException | BuenOjoCSVParserException e) {
fail(e.getMessage());
}
}
示例3: testLandscapeLevelParsing
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
@Test
public void testLandscapeLevelParsing() {
String level = "\"\",\"Niveles\",\"Paisaje\"\n\"1\",\"5:20\",\"Colinas,Llano,Veg media,Veg escasa\"";
InputStreamSource source =new ByteArrayResource(level.getBytes(StandardCharsets.UTF_8));
PhotoLocationLandscapeLevelsCSVParser parser = new PhotoLocationLandscapeLevelsCSVParser(source);
try {
Integer[] levels = parser.parseLevels();
assertThat(levels).isNotNull();
assertThat(levels.length).isEqualTo(2);
assertThat(levels[0]).isNotNull().isEqualTo(5);
assertThat(levels[1]).isNotNull().isEqualTo(20);
} catch (BuenOjoCSVParserException | IOException e) {
fail(e.getMessage());
}
}
示例4: createDataSource
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
/**
* Create an Activation Framework DataSource for the given InputStreamSource.
* @param inputStreamSource the InputStreamSource (typically a Spring Resource)
* @param contentType the content type
* @param name the name of the DataSource
* @return the Activation Framework DataSource
*/
protected DataSource createDataSource(
final InputStreamSource inputStreamSource, final String contentType, final String name) {
return new DataSource() {
@Override
public InputStream getInputStream() throws IOException {
return inputStreamSource.getInputStream();
}
@Override
public OutputStream getOutputStream() {
throw new UnsupportedOperationException("Read-only javax.activation.DataSource");
}
@Override
public String getContentType() {
return contentType;
}
@Override
public String getName() {
return name;
}
};
}
示例5: createDataSource
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
/**
* Create an Activation Framework DataSource for the given InputStreamSource.
* @param inputStreamSource the InputStreamSource (typically a Spring Resource)
* @param contentType the content type
* @param name the name of the DataSource
* @return the Activation Framework DataSource
*/
protected DataSource createDataSource(
final InputStreamSource inputStreamSource, final String contentType, final String name) {
return new DataSource() {
public InputStream getInputStream() throws IOException {
return inputStreamSource.getInputStream();
}
public OutputStream getOutputStream() {
throw new UnsupportedOperationException("Read-only javax.activation.DataSource");
}
public String getContentType() {
return contentType;
}
public String getName() {
return name;
}
};
}
示例6: EmailAttachment
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
public EmailAttachment(InputStreamSource data, String contentType, String filename) {
requireNonNull(data);
requireNonNull(contentType);
requireNonNull(filename);
this.data = data;
this.contentType = contentType;
this.filename = filename;
}
示例7: fromRequestBody
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
@Override
public Credential fromRequestBody(final MultiValueMap<String, String> requestBody) {
final String cert = requestBody.getFirst(CERTIFICATE);
LOGGER.debug("Certificate in the request body: [{}]", cert);
if (StringUtils.isBlank(cert)) {
return super.fromRequestBody(requestBody);
}
final InputStream is = new ByteArrayInputStream(cert.getBytes());
final InputStreamSource iso = new InputStreamResource(is);
final X509Certificate certificate = CertUtils.readCertificate(iso);
final X509CertificateCredential credential = new X509CertificateCredential(new X509Certificate[]{certificate});
credential.setCertificate(certificate);
return credential;
}
示例8: readCertificate
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
/**
* Read certificate.
*
* @param resource the resource to read the cert from
* @return the x 509 certificate
*/
public static X509Certificate readCertificate(final InputStreamSource resource) {
try (InputStream in = resource.getInputStream()) {
return CertUtil.readCertificate(in);
} catch (final IOException e) {
throw new RuntimeException("Error reading certificate " + resource, e);
}
}
示例9: keywordsFromFile
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
public List<PhotoLocationKeyword> keywordsFromFile(InputStreamSource source, Course course) throws IOException{
return keywordsFromFile(source).stream().map((keyword) -> {
keyword.setCourse(course);
return keyword;
}).collect(Collectors.toList());
}
示例10: createSolutionForExerciseFromCSVSource
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
/**
* Create a solution for an {@link ImageCompletionExercise} from it's id and the CSV source
* @param courseId
* @param source
* @param dryRun won't save anything. just for testing
* @return the persisted {@link ImageCompletionSolution}
* @throws BuenOjoCSVParserException
* @throws BuenOjoInconsistencyException
*/
public ImageCompletionSolution createSolutionForExerciseFromCSVSource(ImageCompletionExercise exercise, InputStreamSource source, Boolean dryRun) throws BuenOjoCSVParserException, BuenOjoInconsistencyException {
List<Tag> tagList = tagRepository.findByCourseOrderByNumber(exercise.getCourse());
if (tagList == null || tagList.size() == 0) {
throw new BuenOjoInconsistencyException("No hay etiquetas cargadas para el curso ["+exercise.getCourse()+"]");
}
ImageCompletionSolution solution = new ImageCompletionSolution();
ImageCompletionSolutionCSVParser parser = new ImageCompletionSolutionCSVParser(source, tagList);
List<TagPair> tagPairs = null;
try {
tagPairs = parser.parse();
} catch (IOException e) {
throw new BuenOjoCSVParserException(e.getMessage());
}
tagPairRepository.save(tagPairs);
solutionRepository.save(solution);
HashSet<Tag> tagSet = new HashSet<>();
solution.setTagPairs(new HashSet<TagPair>(tagPairs));
for (TagPair tagPair : tagPairs) {
tagPair.setImageCompletionSolution(solution);
tagSet.add(tagPair.getTag());
}
solution.setImageCompletionExercise(exercise);
solutionRepository.save(solution);
exercise.setImageCompletionSolution(solution);
exercise.setTags(tagSet);
imageCompletionExerciseRepository.save(exercise);
return solution;
}
示例11: parseAndInject
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
public void parseAndInject(PhotoLocationExercise exercise, InputStreamSource inputStreamSource) throws BuenOjoCSVParserException, IOException{
CSVParser parser = CSVFormat.RFC4180.withHeader().withDelimiter(',').withAllowMissingColumnNames(true).parse(new InputStreamReader(inputStreamSource.getInputStream()));
List<CSVRecord> records = parser.getRecords();
if (records.size() > 1) {
throw new BuenOjoCSVParserException("El archivo contiene más de un ejercicio");
}
if (records.size() == 0) {
throw new BuenOjoCSVParserException("El archivo de ejericio es inválido");
}
CSVRecord record = records.get(0);
String name = record.get(MetadataColumns.name);
String description = record.get(MetadataColumns.description);
String difficulty = record.get(MetadataColumns.difficulty);
String seconds = record.get(MetadataColumns.seconds);
String totalScore = record.get(MetadataColumns.totalScore.ordinal());
String imageName = record.get(MetadataColumns.imageName.ordinal());
exercise.setDescription(description);
exercise.setName(name);
exercise.setDifficulty(difficultyFromString(difficulty));
exercise.setTotalTimeInSeconds(new Integer(seconds));
exercise.setTotalScore(new Float(totalScore));
exercise.setExtraPhotosCount(3);
List<PhotoLocationImage> imgs = photoLocationImageRepository.findAll();
Optional<PhotoLocationImage> opt = imgs.stream().filter(p -> p.getImage().getName().equals(imageName)).collect(Collectors.toList()).stream().findFirst();
if (!opt.isPresent()){
throw new BuenOjoCSVParserException("la imagen '"+imageName+"' no existe en la base de datos");
}
PhotoLocationImage img = opt.get();
img.setKeywords(exercise.getLandscapeKeywords());
photoLocationImageRepository.save(img);
exercise.setTerrainPhoto(img);
}
示例12: ImageCompletionTipCSVParser
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
public ImageCompletionTipCSVParser (InputStreamSource source, Course course, TagRepository tagRepository, ImageResourceRepository imageRepository){
this.inputStreamSource = source;
this.course = course;
this.tagRepository = tagRepository;
this.imageRepository = imageRepository;
}
示例13: sendSimpleMailWithAttachment
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
private void sendSimpleMailWithAttachment(final String fromAddress, final List<String> toAddress, final List<String> ccAddress, final String subject, final String mailContent, final List<MultipartFile> attachFiles) {
mailSender.send(new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
messageHelper.setFrom(fromAddress);
messageHelper.setTo(toAddress.toArray(new String[toAddress.size()]));
if (ccAddress != null && ccAddress.size() > 0) {
messageHelper.setCc(ccAddress.toArray(new String[ccAddress.size()]));
}
messageHelper.setSubject(subject);
messageHelper.setText(mailContent);
for (final MultipartFile attachFile : attachFiles) {
// determines if there is an upload file, attach it to the e-mail
if (attachFile != null) {
String attachName = attachFile.getOriginalFilename();
messageHelper.addAttachment(attachName, new InputStreamSource() {
@Override
public InputStream getInputStream() throws IOException {
return attachFile.getInputStream();
}
});
} else {
log.info("Attached file is Empty. Skipping the file " + attachFile + " in mail.");
}
}
}
});
}
示例14: isMutlipart
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
/**
* 暂时只支持这几种类型
*
* @param paramType
* @return dummy
*/
public static boolean isMutlipart(Class paramType) {
return (byte[].class == paramType ||
InputStream.class.isAssignableFrom(paramType) ||
Reader.class.isAssignableFrom(paramType) ||
File.class.isAssignableFrom(paramType) ||
InputStreamSource.class.isAssignableFrom(paramType));
}
示例15: send
import org.springframework.core.io.InputStreamSource; //导入依赖的package包/类
@Override
public void send(String whichMailToSend) throws MessagingException {
whichMailToSend = "default";
final MimeMessage mimeMessage = mailSender.createMimeMessage();
final MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "ISO-2022-JP");
// TODO: to need to set real data, not test
final String imageResourceName = new StringBuilder(resourceLoaderPath)
.append(FILE_SEPARATOR)
.append("test.jpeg")
.toString();
final byte[] imageBytes = new byte[102400];
final String imageContentType = "image/jpeg";
// Prepare the evaluation context
final Context ctx = new Context(LOCALE);
ctx.setVariable("userName", "dao.name");
ctx.setVariable("subscriptionDate", new Date());
ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
ctx.setVariable("imageResourceName", imageResourceName); // so that we can reference it from HTML
// Prepare message using a Spring helper
mimeMessageHelper.setFrom("[email protected]");
mimeMessageHelper.setTo("[email protected]");
mimeMessageHelper.setText("Test English an 日本語", true); // true = isHtml
mimeMessage.setSubject("Test English an 日本語", "ISO-2022-JP");
// Create the HTML body using Thymeleaf
final String htmlContent = templateEngine.process("test.html", ctx);
mimeMessageHelper.setText(htmlContent, false);
// Add the inline image, referenced from the HTML code as "cid:${imageResourceName}"
final InputStreamSource imageSource = new ByteArrayResource(imageBytes);
mimeMessageHelper.addInline(imageResourceName, imageSource, imageContentType);
mailSender.send(mimeMessage);
}