HHH-7066 byte arrays to String conversion benefits from initial buffer size

This commit is contained in:
Sanne Grinovero 2012-02-11 23:56:50 +00:00
parent 98d0b8398d
commit f51779d2f7
2 changed files with 3 additions and 3 deletions

View File

@ -73,9 +73,9 @@ public class DataHelper {
*/
public static String extractString(Reader reader, int lengthHint) {
// read the Reader contents into a buffer and return the complete string
final StringBuilder stringBuilder = new StringBuilder( lengthHint );
final int bufferSize = Math.min( lengthHint, 2048 );
final StringBuilder stringBuilder = new StringBuilder( bufferSize );
try {
final int bufferSize = Math.min( lengthHint, 2048 );
char[] buffer = new char[bufferSize];
while (true) {
int amountRead = reader.read( buffer, 0, bufferSize );

View File

@ -62,7 +62,7 @@ public class PrimitiveByteArrayTypeDescriptor extends AbstractTypeDescriptor<byt
}
public String toString(byte[] bytes) {
final StringBuffer buf = new StringBuffer();
final StringBuilder buf = new StringBuilder( bytes.length * 2 );
for ( byte aByte : bytes ) {
final String hexStr = Integer.toHexString( aByte - Byte.MIN_VALUE );
if ( hexStr.length() == 1 ) {