diff options
author | Bo Yang <teboring@google.com> | 2016-09-19 13:45:07 -0700 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2016-10-10 11:23:36 -0700 |
commit | cc8ca5b6a5478b40546d4206392eb1471454460d (patch) | |
tree | c0b45abfa16d7d373a6ea8f7fe50f1de00ab938e /java/core/src/main/java/com/google/protobuf/ByteString.java | |
parent | 337a028bb65ccca4dda768695950b5aba53ae2c9 (diff) | |
download | protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.gz protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.tar.bz2 protobuf-cc8ca5b6a5478b40546d4206392eb1471454460d.zip |
Integrate internal changes
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/ByteString.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/ByteString.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index 3f3f9f3c..5b24976d 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -311,6 +311,18 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { } /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage. + */ + static ByteString wrap(ByteBuffer buffer) { + if (buffer.hasArray()) { + final int offset = buffer.arrayOffset(); + return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); + } else { + return new NioByteString(buffer); + } + } + + /** * Wraps the given bytes into a {@code ByteString}. Intended for internal only * usage to force a classload of ByteString before LiteralByteString. */ @@ -679,6 +691,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { */ abstract void writeTo(ByteOutput byteOutput) throws IOException; + /** * Constructs a read-only {@code java.nio.ByteBuffer} whose content * is equal to the contents of this byte string. @@ -820,6 +833,7 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { return true; } + /** * Check equality of the substring of given length of this object starting at * zero with another {@code ByteString} substring starting at offset. |