aboutsummaryrefslogtreecommitdiff
path: root/java/src/main/java/com/google/protobuf/ByteString.java
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2015-08-22 18:25:48 -0700
committerFeng Xiao <xfxyjwf@gmail.com>2015-08-22 18:25:48 -0700
commiteee38b0c018b3279f77d03dff796f440f40d3516 (patch)
tree7ff0978e30238d493fc7899b75abeb6d66939f07 /java/src/main/java/com/google/protobuf/ByteString.java
parentc3bc155aceda36ecb01cde2367a3b427f2d7ce40 (diff)
downloadprotobuf-eee38b0c018b3279f77d03dff796f440f40d3516.tar.gz
protobuf-eee38b0c018b3279f77d03dff796f440f40d3516.tar.bz2
protobuf-eee38b0c018b3279f77d03dff796f440f40d3516.zip
Down-integrate from google3.
Diffstat (limited to 'java/src/main/java/com/google/protobuf/ByteString.java')
-rw-r--r--java/src/main/java/com/google/protobuf/ByteString.java22
1 files changed, 11 insertions, 11 deletions
diff --git a/java/src/main/java/com/google/protobuf/ByteString.java b/java/src/main/java/com/google/protobuf/ByteString.java
index 1d5d4e8a..0bd1750d 100644
--- a/java/src/main/java/com/google/protobuf/ByteString.java
+++ b/java/src/main/java/com/google/protobuf/ByteString.java
@@ -294,10 +294,10 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
* <b>Performance notes:</b> The returned {@code ByteString} is an
* immutable tree of byte arrays ("chunks") of the stream data. The
* first chunk is small, with subsequent chunks each being double
- * the size, up to 8K. If the caller knows the precise length of
- * the stream and wishes to avoid all unnecessary copies and
- * allocations, consider using the two-argument version of this
- * method, below.
+ * the size, up to 8K.
+ *
+ * <p>Each byte read from the input stream will be copied twice to ensure
+ * that the resulting ByteString is truly immutable.
*
* @param streamToDrain The source stream, which is read completely
* but not closed.
@@ -320,12 +320,10 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
*
* <b>Performance notes:</b> The returned {@code ByteString} is an
* immutable tree of byte arrays ("chunks") of the stream data. The
- * chunkSize parameter sets the size of these byte arrays. In
- * particular, if the chunkSize is precisely the same as the length
- * of the stream, unnecessary allocations and copies will be
- * avoided. Otherwise, the chunks will be of the given size, except
- * for the last chunk, which will be resized (via a reallocation and
- * copy) to contain the remainder of the stream.
+ * chunkSize parameter sets the size of these byte arrays.
+ *
+ * <p>Each byte read from the input stream will be copied twice to ensure
+ * that the resulting ByteString is truly immutable.
*
* @param streamToDrain The source stream, which is read completely
* but not closed.
@@ -386,6 +384,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
if (bytesRead == 0) {
return null;
} else {
+ // Always make a copy since InputStream could steal a reference to buf.
return ByteString.copyFrom(buf, 0, bytesRead);
}
}
@@ -736,7 +735,8 @@ public abstract class ByteString implements Iterable<Byte>, Serializable {
* returns the number of bytes remaining in the stream. The methods
* {@link InputStream#read(byte[])}, {@link InputStream#read(byte[],int,int)}
* and {@link InputStream#skip(long)} will read/skip as many bytes as are
- * available.
+ * available. The method {@link InputStream#markSupported()} returns
+ * {@code true}.
* <p>
* The methods in the returned {@link InputStream} might <b>not</b> be
* thread safe.