aboutsummaryrefslogtreecommitdiffhomepage
path: root/java/src/main/java/com/google/protobuf/ByteString.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/main/java/com/google/protobuf/ByteString.java')
-rw-r--r--java/src/main/java/com/google/protobuf/ByteString.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/java/src/main/java/com/google/protobuf/ByteString.java b/java/src/main/java/com/google/protobuf/ByteString.java
index 9814dfc1..f376e7a1 100644
--- a/java/src/main/java/com/google/protobuf/ByteString.java
+++ b/java/src/main/java/com/google/protobuf/ByteString.java
@@ -35,6 +35,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
/**
* Immutable array of bytes.
@@ -154,6 +155,15 @@ public final class ByteString {
}
/**
+ * Constructs a new read-only {@code java.nio.ByteBuffer} with the
+ * same backing byte array.
+ */
+ public ByteBuffer asReadOnlyByteBuffer() {
+ ByteBuffer byteBuffer = ByteBuffer.wrap(this.bytes);
+ return byteBuffer.asReadOnlyBuffer();
+ }
+
+ /**
* Constructs a new {@code String} by decoding the bytes using the
* specified charset.
*/