8273528: Avoid ByteArrayOutputStream.toByteArray when converting stream to String

Reviewed-by: bpb, xuelei, serb, aivanov
This commit is contained in:
Andrey Turbanov 2021-09-09 21:47:59 +00:00 committed by Sergey Bylokhov
parent 54dee132d1
commit 2e321dc782
4 changed files with 5 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -261,7 +261,7 @@ public class BitArray {
out.write(get(i) ? '1' : '0');
}
return new String(out.toByteArray());
return out.toString();
}

View File

@ -228,7 +228,7 @@ public class PNGImageReader extends ImageReader {
if (b != 0) {
throw new IIOException("Found non null terminated string");
}
return new String(baos.toByteArray(), charset);
return baos.toString(charset);
}
private void readHeader() throws IIOException {

View File

@ -134,7 +134,7 @@ public final class DebugSettings {
String value = props.getProperty(key, "");
pout.println(key + " = " + value);
}
return new String(bout.toByteArray());
return bout.toString();
}
/*

View File

@ -945,10 +945,9 @@ search:
}
if (DataFlavorUtil.isFlavorCharsetTextType(flavor) && isTextFormat(format)) {
byte[] bytes = bos.toByteArray();
String sourceEncoding = DataFlavorUtil.getTextCharset(flavor);
return translateTransferableString(
new String(bytes, sourceEncoding),
bos.toString(sourceEncoding),
format);
}
theByteArray = bos.toByteArray();