HHH-7066 Allocate smaller buffer if possible

This commit is contained in:
Sanne Grinovero 2012-02-11 14:34:59 +00:00
parent 939d7fc4c9
commit 6497ff6a52
1 changed files with 4 additions and 3 deletions

View File

@ -98,15 +98,16 @@ public class DataHelper {
if ( skipped != start ) {
throw new HibernateException( "Unable to skip needed bytes" );
}
char[] buffer = new char[2048];
final int bufferSize = Math.min( length, 2048 );
char[] buffer = new char[bufferSize];
int charsRead = 0;
while ( true ) {
int amountRead = characterStream.read( buffer, 0, buffer.length );
int amountRead = characterStream.read( buffer, 0, bufferSize );
if ( amountRead == -1 ) {
break;
}
stringBuilder.append( buffer, 0, amountRead );
if ( amountRead < buffer.length ) {
if ( amountRead < bufferSize ) {
// we have read up to the end of stream
break;
}