Skip to content

Increase StreamUtils.BUFFER_SIZE to 8192 #28965

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Simple utility methods for dealing with streams. The copy methods of this class are
* similar to those defined in {@link FileCopyUtils} except that all affected streams are
* left open when done. All copy methods use a block size of 4096 bytes.
* left open when done. All copy methods use a block size of 8192 bytes.
*
* <p>Mainly for use within the framework, but also useful for application code.
*
Expand All @@ -48,7 +48,7 @@ public abstract class StreamUtils {
/**
* The default buffer size used when copying bytes.
*/
public static final int BUFFER_SIZE = 4096;
public static final int BUFFER_SIZE = 8192;

private static final byte[] EMPTY_CONTENT = new byte[0];

Expand Down Expand Up @@ -83,7 +83,7 @@ public static String copyToString(@Nullable InputStream in, Charset charset) thr
return "";
}

StringBuilder out = new StringBuilder(BUFFER_SIZE);
StringBuilder out = new StringBuilder();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning for using the default here, is that for any output less than BUFFER_SIZE, we end up over-allocating by specifying this value. If we use the default, and the first read fills the buffer, we will resize to BUFFER_SIZE immediately anyway when we write to the StringBuilder.

InputStreamReader reader = new InputStreamReader(in, charset);
char[] buffer = new char[BUFFER_SIZE];
int charsRead;
Expand Down