-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed as not planned
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
ResourceHttpMessageConverter class method readInternal create InputStreamResource only when we use InputStreamResource in controller method, otherwice it create ByteArrayResource.
I think it's incorrect, and we need write something like this, see code below.
Or someone can explain why it created in that way?
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
if (this.supportsReadStreaming && (InputStreamResource.class == clazz || Resource.class == clazz)) {
return new InputStreamResource(inputMessage.getBody()) {
@Override
public String getFilename() {
return inputMessage.getHeaders().getContentDisposition().getFilename();
}
@Override
public long contentLength() throws IOException {
long length = inputMessage.getHeaders().getContentLength();
return (length != -1 ? length : super.contentLength());
}
};
} else if (ByteArrayResource.class.isAssignableFrom(clazz)) {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body) {
@Override
@Nullable
public String getFilename() {
return inputMessage.getHeaders().getContentDisposition().getFilename();
}
};
} else {
throw new HttpMessageNotReadableException("Unsupported resource class: " + clazz, inputMessage);
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply