當前位置: 首頁>>代碼示例>>Java>>正文


Java InputStreamResource類代碼示例

本文整理匯總了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();
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:29,代碼來源:BlurImageController.java

示例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());
			}
		});
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:HomeController.java

示例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());
			}
		});
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:HomeController.java

示例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);
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:28,代碼來源:CpcFileControllerV1.java

示例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;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:17,代碼來源:X509CertificateCredentialJsonDeserializer.java

示例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;

}
 
開發者ID:hmcts,項目名稱:document-management-store-app,代碼行數:21,代碼來源:DocumentContentVersionController.java

示例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()));
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:31,代碼來源:FileApi.java

示例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);
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:24,代碼來源:XmHttpEntityUtils.java

示例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;
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:19,代碼來源:RdfModelTransformer.java

示例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());
}
 
開發者ID:dotwebstack,項目名稱:dotwebstack-framework,代碼行數:19,代碼來源:ShaclValidatorTest.java

示例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();
}    	
  	
  }
 
開發者ID:danicuestasuarez,項目名稱:NMapGUI,代碼行數:17,代碼來源:WebController.java

示例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("不支持的返回類型");
    }
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:23,代碼來源:WxMediaResourceMessageConverter.java

示例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()));
}
 
開發者ID:SpartaSystems,項目名稱:holdmail,代碼行數:20,代碼來源:MessageController.java

示例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));

}
 
開發者ID:SpartaSystems,項目名稱:holdmail,代碼行數:26,代碼來源:MessageControllerTest.java


注:本文中的org.springframework.core.io.InputStreamResource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。