missing = missingTypeVariables;
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ByteBuffer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ByteBuffer.java
index 0f87667a8f0..c035263e34c 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ByteBuffer.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/ByteBuffer.java
@@ -56,8 +56,13 @@ public class ByteBuffer {
* of given size.
*/
public ByteBuffer(int initialSize) {
- elems = new byte[initialSize];
- length = 0;
+ this(new byte[initialSize]);
+ }
+
+ /** Create a new byte buffer using the given array for storage.
+ */
+ public ByteBuffer(byte[] elems) {
+ this.elems = elems;
}
/** Append byte to this buffer.
@@ -147,30 +152,28 @@ public class ByteBuffer {
appendBytes(name.getByteArray(), name.getByteOffset(), name.getByteLength());
}
- /** Append the content of a given input stream, and then close the stream.
+ /** Append the content of the given input stream.
*/
- public void appendStream(InputStream is) throws IOException {
- try (InputStream input = is) {
- while (true) {
+ public void appendStream(InputStream input) throws IOException {
+ while (true) {
- // Read another chunk of data, using size hint from available().
- // If available() is accurate, the array size should be just right.
- int amountToRead = Math.max(input.available(), 64);
- elems = ArrayUtils.ensureCapacity(elems, length + amountToRead);
- int amountRead = input.read(elems, length, amountToRead);
- if (amountRead == -1)
+ // Read another chunk of data, using size hint from available().
+ // If available() is accurate, the array size should be just right.
+ int amountToRead = Math.max(input.available(), 64);
+ elems = ArrayUtils.ensureCapacity(elems, length + amountToRead);
+ int amountRead = input.read(elems, length, amountToRead);
+ if (amountRead == -1)
+ break;
+ length += amountRead;
+
+ // Check for the common case where input.available() returned the
+ // entire remaining input; in that case, avoid an extra array extension.
+ // Note we are guaranteed that elems.length >= length + 1 at this point.
+ if (amountRead == amountToRead) {
+ int byt = input.read();
+ if (byt == -1)
break;
- length += amountRead;
-
- // Check for the common case where input.available() returned the
- // entire remaining input; in that case, avoid an extra array extension.
- // Note we are guaranteed that elems.length >= length + 1 at this point.
- if (amountRead == amountToRead) {
- int byt = input.read();
- if (byt == -1)
- break;
- elems[length++] = (byte)byt;
- }
+ elems[length++] = (byte)byt;
}
}
}
@@ -292,6 +295,15 @@ public class ByteBuffer {
throw new UnderflowException(length);
}
+ /** Create a {@link java.nio.ByteBuffer} view of this instance.
+ *
+ *
+ * If this instance is modified, the returned buffer may no longer reflect it.
+ */
+ public java.nio.ByteBuffer asByteBuffer() {
+ return java.nio.ByteBuffer.wrap(elems, 0, length);
+ }
+
// UnderflowException
/** Thrown when trying to read past the end of the buffer.