本文整理汇总了Java中org.springframework.core.io.InputStreamResource类的典型用法代码示例。如果您正苦于以下问题:Java InputStreamResource类的具体用法?Java InputStreamResource怎么用?Java InputStreamResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InputStreamResource类属于org.springframework.core.io包,在下文中一共展示了InputStreamResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blur
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@RequestMapping(value = "/blur", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> blur(@RequestParam("source") String sourceUrl, HttpServletResponse response) {
if (!StringUtils.startsWithAny(sourceUrl, ALLOWED_PREFIX)) {
return ResponseEntity.badRequest().build();
}
String hash = DigestUtils.sha1Hex(sourceUrl);
try {
ImageInfo info = readCached(hash);
if (info == null) {
info = renderImage(sourceUrl);
if (info != null) {
saveCached(hash, info);
}
}
if (info != null) {
return ResponseEntity.ok()
.contentLength(info.contentLength)
.contentType(MediaType.IMAGE_JPEG)
.body(new InputStreamResource(info.inputStream));
}
} catch (IOException e) {
// fall down
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
示例2: oneRawImage
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
@PathVariable String filename) {
// tag::try-catch[]
return imageService.findOneImage(filename)
.map(resource -> {
try {
return ResponseEntity.ok()
.contentLength(resource.contentLength())
.body(new InputStreamResource(
resource.getInputStream()));
} catch (IOException e) {
return ResponseEntity.badRequest()
.body("Couldn't find " + filename +
" => " + e.getMessage());
}
});
// end::try-catch[]
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:22,代码来源:UploadController.java
示例3: oneRawImage
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
@PathVariable String filename) {
return imageService.findOneImage(filename)
.map(resource -> {
try {
return ResponseEntity.ok()
.contentLength(resource.contentLength())
.body(new InputStreamResource(
resource.getInputStream()));
} catch (IOException e) {
return ResponseEntity.badRequest()
.body("Couldn't find " + filename +
" => " + e.getMessage());
}
});
}
示例4: oneRawImage
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
@PathVariable String filename) {
return imageService.findOneImage(filename)
.map(resource -> {
try {
return ResponseEntity.ok()
.contentLength(resource.contentLength())
.body(new InputStreamResource(
resource.getInputStream()));
} catch (IOException e) {
return ResponseEntity.badRequest()
.body("Couldn't find " + filename +
" => " + e.getMessage());
}
});
}
示例5: getFileById
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
/**
* Retrieve a stored S3 object.
*
* @param fileId id for the stored object
* @return object json or xml content
* @throws IOException if S3Object content stream is invalid
*/
@GetMapping(value = "/file/{fileId}",
headers = {"Accept=" + Constants.V1_API_ACCEPT})
public ResponseEntity<InputStreamResource> getFileById(@PathVariable("fileId") String fileId)
throws IOException {
API_LOG.info("CPC+ file retrieval request received");
if (blockCpcPlusApi()) {
API_LOG.info("CPC+ file request blocked by feature flag");
return new ResponseEntity<>(null, null, HttpStatus.FORBIDDEN);
}
InputStreamResource content = cpcFileService.getFileById(fileId);
API_LOG.info("CPC+ file retrieval request succeeded");
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_XML);
return new ResponseEntity<>(content, httpHeaders, HttpStatus.OK);
}
示例6: deserialize
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@Override
public X509CertificateCredential deserialize(final JsonParser jp,
final DeserializationContext deserializationContext)
throws IOException {
final ObjectCodec oc = jp.getCodec();
final JsonNode node = oc.readTree(jp);
final List<X509Certificate> certs = new ArrayList<>();
node.findValues("certificates").forEach(n -> {
final String cert = n.get(0).textValue();
final byte[] data = EncodingUtils.decodeBase64(cert);
certs.add(CertUtils.readCertificate(new InputStreamResource(new ByteArrayInputStream(data))));
});
final X509CertificateCredential c = new X509CertificateCredential(certs.toArray(new X509Certificate[] {}));
return c;
}
示例7: getDocumentContentVersionDocumentBinary
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@GetMapping(value = "/versions/{versionId}/binary")
@ApiOperation("Streams a specific version of the content of a Stored Document.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Returns contents of a document version")
})
public ResponseEntity<InputStreamResource> getDocumentContentVersionDocumentBinary(
@PathVariable UUID documentId,
@PathVariable UUID versionId) {
DocumentContentVersion documentContentVersion = documentContentVersionService.findOne(versionId);
if (documentContentVersion == null || documentContentVersion.getStoredDocument().isDeleted()) {
throw new DocumentContentVersionNotFoundException(String.format("ID: %s", versionId.toString()));
} else {
auditedDocumentContentVersionOperationsService.readDocumentContentVersionBinary(documentContentVersion);
}
return null;
}
示例8: download
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
/**
* Gets the content of a file with specified id.
*
* <p>
* Also sets Content-Length and Content-Disposition http headers to values previously saved during upload.
* </p>
* @param id Id of file to retrieve
* @throws MissingObject if the file was not found
* @return Content of a file in input stream
*/
@ApiOperation(value = "Gets the content of a file with specified id.",
notes = "Returns content of a file in input stream.",
response = ResponseEntity.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful response", response = ResponseEntity.class),
@ApiResponse(code = 404, message = "The file was not found")})
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> download(@ApiParam(value = "Id of file to retrieve", required = true)
@PathVariable("id") String id) {
FileRef file = repository.get(id);
notNull(file, () -> new MissingObject(FileRef.class, id));
return ResponseEntity
.ok()
.header("Content-Disposition", "attachment; filename=" + file.getName())
.header("Content-Length", String.valueOf(file.getSize()))
.contentType(MediaType.parseMediaType(file.getContentType()))
.body(new InputStreamResource(file.getStream()));
}
示例9: buildAvatarHttpEntity
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
public static HttpEntity<Resource> buildAvatarHttpEntity(MultipartFile multipartFile) throws IOException {
// result headers
HttpHeaders headers = new HttpHeaders();
// 'Content-Type' header
String contentType = multipartFile.getContentType();
if (StringUtils.isNotBlank(contentType)) {
headers.setContentType(MediaType.valueOf(contentType));
}
// 'Content-Length' header
long contentLength = multipartFile.getSize();
if (contentLength >= 0) {
headers.setContentLength(contentLength);
}
// File name header
String fileName = multipartFile.getOriginalFilename();
headers.set(XM_HEADER_CONTENT_NAME, fileName);
Resource resource = new InputStreamResource(multipartFile.getInputStream());
return new HttpEntity<>(resource, headers);
}
示例10: mergeResourceWithPrefixes
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
public static Model mergeResourceWithPrefixes(InputStream inputStreamPrefixes,
InputStream inputStreamData) throws IOException {
final Resource mergedDataResource =
new InputStreamResource(new SequenceInputStream(inputStreamPrefixes, inputStreamData));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
trigParser.setRDFHandler(turtleWriter);
trigParser.parse(mergedDataResource.getInputStream(), "");
Model result = Rio.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "",
RDFFormat.TURTLE);
byteArrayOutputStream.close();
inputStreamData.close();
return result;
}
示例11: setUp
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
shaclValidator = new ShaclValidator();
shapesResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/shapes.trig").getInputStream());
validDataResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/validData.trig").getInputStream());
invalidDataResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/invalidData.trig").getInputStream());
invalidDataWithoutPrefResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/invalidDataWithoutPref.trig").getInputStream());
validDataWithoutPrefResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/validDataWithoutPref.trig").getInputStream());
prefixesResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/_prefixes.trig").getInputStream());
invalidDataMultipleErrorsResource = new InputStreamResource(
new ClassPathResource("/shaclvalidation/invalidDataMultipleErrors.trig").getInputStream());
}
示例12: download
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@GetMapping("/nmap/download/{filename}")
public ResponseEntity<InputStreamResource> download(@PathVariable("filename") String filename) {
InputStream file;
try {
file = new Filefinder().find(filename);
InputStreamResource resource = new InputStreamResource(file);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octect-stream"))
.body(resource);
} catch (FileNotFoundException e) {
return ResponseEntity.notFound().build();
}
}
示例13: readInternal
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
WxMediaResource wxMediaResource = new WxMediaResource(inputMessage);
if (wxMediaResource.isUrlMedia() && !clazz.isAssignableFrom(WxMediaResource.class)) {
throw new WxApiException("不支持的返回类型,接口返回了url");
}
if (InputStreamResource.class == clazz) {
return new InputStreamResource(wxMediaResource.getInputStream());
} else if (clazz.isAssignableFrom(WxMediaResource.class)) {
return wxMediaResource;
} else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
return new ByteArrayResource(wxMediaResource.getBody());
} else if (clazz.isAssignableFrom(FileSystemResource.class)) {
return new FileSystemResource(wxMediaResource.getFile());
}
// else if (clazz.isAssignableFrom(File.class)) {
// return wxMediaResource.getFile();
// }
throw new WxApiException("不支持的返回类型");
}
示例14: getMessageContentByAttachmentId
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@RequestMapping(value = "/{messageId}/att/{attId}")
public ResponseEntity getMessageContentByAttachmentId(@PathVariable("messageId") long messageId,
@PathVariable("attId") int attId) {
Message message = messageService.getMessage(messageId);
MessageContentPart content = message.getContent().findBySequenceId(attId);
String disposition = "attachment;";
if(StringUtils.isNotBlank(content.getAttachmentFilename())) {
disposition += " filename=\"" + content.getAttachmentFilename() + "\";";
}
return ResponseEntity.ok()
.header("Content-Type", content.getContentType())
.header("Content-Disposition", disposition)
.body(new InputStreamResource(content.getContentStream()));
}
示例15: shouldGetMessageContentByPartId
import org.springframework.core.io.InputStreamResource; //导入依赖的package包/类
@Test
public void shouldGetMessageContentByPartId() throws Exception{
final int MSG_ID = 983;
final String PART_ID = "derpPart";
final String CONTENT_TYPE = "some/type";
final InputStream CONTENT_STREAM = mock(InputStream.class);
MessageContentPart contentPartMock = mock(MessageContentPart.class);
when(contentPartMock.getContentType()).thenReturn(CONTENT_TYPE);
when(contentPartMock.getContentStream()).thenReturn(CONTENT_STREAM);
Message messageMock = mock(Message.class);
when(messageServiceMock.getMessage(MSG_ID)).thenReturn(messageMock);
MessageContent contentMock = mock(MessageContent.class);
when(messageMock.getContent()).thenReturn(contentMock);
when(contentMock.findByContentId(PART_ID)).thenReturn(contentPartMock);
ResponseEntity response = messageControllerSpy.getMessageContentByPartId(MSG_ID, PART_ID);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().get("Content-Type")).hasSize(1).contains(CONTENT_TYPE);
assertThat(response.getBody()).isEqualTo(new InputStreamResource(CONTENT_STREAM));
}