本文整理汇总了Java中org.springframework.util.StreamUtils.copyToByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtils.copyToByteArray方法的具体用法?Java StreamUtils.copyToByteArray怎么用?Java StreamUtils.copyToByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StreamUtils
的用法示例。
在下文中一共展示了StreamUtils.copyToByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvalidVersions
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Test
public void testInvalidVersions() throws IOException {
UploadRequest uploadRequest = new UploadRequest();
uploadRequest.setRepoName("local");
uploadRequest.setName("log");
uploadRequest.setVersion("abc");
uploadRequest.setExtension("zip");
Resource resource = new ClassPathResource("/org/springframework/cloud/skipper/server/service/log-9.9.9.zip");
assertThat(resource.exists()).isTrue();
byte[] originalPackageBytes = StreamUtils.copyToByteArray(resource.getInputStream());
assertThat(originalPackageBytes).isNotEmpty();
Assert.isTrue(originalPackageBytes.length != 0,
"PackageServiceTests.Assert.isTrue: Package file as bytes must not be empty");
assertInvalidPackageVersion(uploadRequest);
uploadRequest.setVersion("1abc");
assertInvalidPackageVersion(uploadRequest);
uploadRequest.setVersion("1.abc.2");
assertInvalidPackageVersion(uploadRequest);
uploadRequest.setVersion("a.b.c");
assertInvalidPackageVersion(uploadRequest);
uploadRequest.setVersion("a.b.c.2");
assertInvalidPackageVersion(uploadRequest);
}
示例2: resolveImageURI
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
protected String resolveImageURI(String resourceURI) {
if (resourceURI == null || resourceURI.isEmpty()) return resourceURI;
if (imageCache.containsKey(resourceURI)) return imageCache.get(resourceURI);
String resolvedValue = resourceURI;
if (resourceURI.toLowerCase().startsWith("file://")) {
String mimetype = URLConnection.guessContentTypeFromName(resourceURI);
if (mimetype == null) {
logger.warn("Cannot determine mimetype for resource: " + resourceURI);
} else {
try (InputStream input = new URL(resourceURI).openConnection().getInputStream()) {
byte[] data = StreamUtils.copyToByteArray(input);
String encoded = Base64.getEncoder().encodeToString(data);
resolvedValue = String.format("data:%s;base64,%s", mimetype, encoded);
} catch (IOException e) {
logger.warn("Failed to convert file URI to data URI: " + resourceURI, e);
}
}
}
imageCache.put(resourceURI, resolvedValue);
return resolvedValue;
}
示例3: getBinaryResource
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* Return the binary content of the resource at the specified location.
* @param location a resource location
* @return the content of the resource
*/
@Cacheable("project-resources")
public byte[] getBinaryResource(String location) {
try (InputStream stream = getInputStream(location)) {
return StreamUtils.copyToByteArray(stream);
}
catch (IOException ex) {
throw new IllegalStateException("Cannot get resource", ex);
}
}
示例4: upload
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private ResponseEntity<byte[]> upload(File download, File dir, String fileName,
String contentType) throws IOException {
byte[] bytes = StreamUtils.copyToByteArray(new FileInputStream(download));
log.info("Uploading: {} ({} bytes)", download, bytes.length);
ResponseEntity<byte[]> result = createResponseEntity(bytes, contentType,
fileName);
projectGenerator.cleanTempFiles(dir);
return result;
}
示例5: readInternal
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body);
}
示例6: readSAXSource
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private SAXSource readSAXSource(InputStream body) throws IOException {
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
byte[] bytes = StreamUtils.copyToByteArray(body);
if (!isProcessExternalEntities()) {
reader.setEntityResolver(NO_OP_ENTITY_RESOLVER);
}
return new SAXSource(reader, new InputSource(new ByteArrayInputStream(bytes)));
}
catch (SAXException ex) {
throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
}
}
示例7: getBody
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
public InputStream getBody() throws IOException {
if (this.body == null) {
this.body = StreamUtils.copyToByteArray(this.response.getBody());
}
return new ByteArrayInputStream(this.body);
}
示例8: BodyReaderWrapper
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
public BodyReaderWrapper ( HttpServletRequest request ) throws IOException {
super( request );
if ( RequestUtils.isApplicationJsonHeader( request ) ) {
body = StreamUtils.copyToByteArray( request.getInputStream() );
} else {
body = null;
}
}
示例9: WxMediaResource
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* 是否真的需要这么多成员变量?
*
* @param httpInputMessage
* @throws IOException
*/
public WxMediaResource(HttpInputMessage httpInputMessage) throws IOException {
this.isFileResource = false;
if (httpInputMessage instanceof WxBufferingInputMessageWrapper) {
this.body = ((WxBufferingInputMessageWrapper) httpInputMessage).getRawBody();
} else {
this.body = StreamUtils.copyToByteArray(httpInputMessage.getBody());
}
this.httpHeaders = httpInputMessage.getHeaders();
this.contentType = httpHeaders.getContentType();
this.contentLength = httpHeaders.getContentLength();
// 判断是否是json
if (!this.httpHeaders.containsKey(HttpHeaders.CONTENT_DISPOSITION)) {
this.isUrlMedia = true;
if (body[0] == '{') {
this.url = extractURL(body);
this.filename = extractFilenameFromURL(url);
} else if (httpHeaders.containsKey(WxWebUtils.X_WX_REQUEST_URL)) {
this.url = URI.create(httpHeaders.getFirst(WxWebUtils.X_WX_REQUEST_URL)).toURL();
this.filename = extractFilenameFromURL(url);
} else {
this.filename = UUID.randomUUID().toString() + ".jpg";
}
} else {
this.description = this.httpHeaders.getFirst(HttpHeaders.CONTENT_DISPOSITION);
this.filename = extractFilename(this.description);
}
}
示例10: getBody
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* body只在
*
* @return dummy
*/
public byte[] getBody() {
if (this.body == null && this.file != null) {
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
this.body = StreamUtils.copyToByteArray(is);
} catch (Exception e) {
throw new WxAppException(e);
}
}
return body;
}
示例11: init
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* 构造后初始化,不想加在构造方法中,一定要记着初始化
*
* @throws IOException
*/
public WxBufferingInputMessageWrapper init() throws IOException {
if (this.body != null) {
return this;
}
if (httpInputMessage instanceof WxBufferingInputMessageWrapper) {
this.body = ((WxBufferingInputMessageWrapper) httpInputMessage).getRawBody();
} else {
this.body = StreamUtils.copyToByteArray(httpInputMessage.getBody());
}
return this;
}
示例12: asBytes
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
public byte[] asBytes() {
try {
return StreamUtils.copyToByteArray(result);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: readInternal
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
if (InputStreamResource.class == clazz){
return new InputStreamResource(inputMessage.getBody());
}
else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body);
}
else {
throw new IllegalStateException("Unsupported resource class: " + clazz);
}
}
示例14: readSAXSource
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
private SAXSource readSAXSource(InputStream body) throws IOException {
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());
reader.setFeature("http://xml.org/sax/features/external-general-entities", isProcessExternalEntities());
if (!isProcessExternalEntities()) {
reader.setEntityResolver(NO_OP_ENTITY_RESOLVER);
}
byte[] bytes = StreamUtils.copyToByteArray(body);
return new SAXSource(reader, new InputSource(new ByteArrayInputStream(bytes)));
}
catch (SAXException ex) {
throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
}
}
示例15: readToken
import org.springframework.util.StreamUtils; //导入方法依赖的package包/类
/**
* Read the token from {@link Resource}.
*
* @param resource the resource to read from, must not be {@literal null}.
* @return the new byte array that has been copied to (possibly empty).
* @throws IOException in case of I/O errors.
*/
protected static byte[] readToken(Resource resource) throws IOException {
Assert.notNull(resource, "Resource must not be null");
try (InputStream is = resource.getInputStream()) {
return StreamUtils.copyToByteArray(is);
}
}