Skip to content
Merged
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 @@ -22,6 +22,9 @@ public final class ByteSourceJsonBootstrapper
public final static byte UTF8_BOM_2 = (byte) 0xBB;
public final static byte UTF8_BOM_3 = (byte) 0xBF;

// [jackson-core#488] Limit in bytes for input byte array length to use StringReader instead of InputStreamReader
private static final int STRING_READER_BYTE_ARRAY_LENGTH_LIMIT = 8192;

/*
/**********************************************************
/* Configuration
Expand Down Expand Up @@ -230,6 +233,12 @@ public Reader constructReader() throws IOException
InputStream in = _in;

if (in == null) {
int length = _inputEnd - _inputPtr;
if (length <= STRING_READER_BYTE_ARRAY_LENGTH_LIMIT) {
// [jackson-core#488] Avoid overhead of heap ByteBuffer allocated by InputStreamReader
// when processing small inputs up to 8KiB.
return new StringReader(new String(_inputBuffer, _inputPtr, length, enc.getJavaName()));
}
in = new ByteArrayInputStream(_inputBuffer, _inputPtr, _inputEnd);
} else {
/* Also, if we have any read but unused input (usually true),
Expand Down