-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce toString(Charset)
in FastByteArrayOutputStream
#31737
Introduce toString(Charset)
in FastByteArrayOutputStream
#31737
Conversation
Add a toString overload that accepts a Charset to mirror the method that has been on ByteArrayOutputStream since JDK10; additionally, add a special case for when a single buffer is in use internally to avoid the need to resize.
Note this is somewhat of a follow up to #31731 and #30709; |
toString(Charset)
in FastByteArrayOutputStream
* to be used to decode the {@code bytes} | ||
* @return a String decoded from the buffer's contents | ||
*/ | ||
public String toString(Charset charset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, please keep in mind that we do not indent Javadoc tag content and that we need to add a @since
tag for new elements in the public API.
However, I'll address those issues when merging, so there's no need to update this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, references to instance fields must be prefixed with this.
.
See Spring Framework's Code Style documentation for details.
This commit builds on top of changes made in gh-29775 and gh-31737. Before this change, we would allocate several byte arrays even in cases of known request size. This could decrease performance when getting the cached content as it requires merging several arrays and data is not colocated in memory. This change ensures that we create a `FastByteArrayOutputStream` instance with the known request size so that the first allocated segment can contain the entire content. If the request size is not know, we will default back on the default allocation size for the `FastByteArrayOutputStream`. Closes gh-31834
Add a toString overload that accepts a Charset to mirror the method that has been on ByteArrayOutputStream since JDK10; additionally, add a special case for when a single buffer is in use internally to avoid the need to resize.