diff options
author | Tamir Duberstein <tamird@gmail.com> | 2015-03-31 20:01:43 -0700 |
---|---|---|
committer | Tamir Duberstein <tamird@gmail.com> | 2015-04-02 15:06:00 -0700 |
commit | 210de285d7ca5e4d4e96867c1c04308d68c5d4dd (patch) | |
tree | 983ab06e7e3a37e38a5d6c1768c15f50246df5d3 /java/src/main/java/com/google/protobuf/ByteString.java | |
parent | e84893f6768f136cc86e2db69fc1d40ff2be7e3b (diff) | |
download | protobuf-210de285d7ca5e4d4e96867c1c04308d68c5d4dd.tar.gz protobuf-210de285d7ca5e4d4e96867c1c04308d68c5d4dd.tar.bz2 protobuf-210de285d7ca5e4d4e96867c1c04308d68c5d4dd.zip |
DRY: Use `Charset` statics to eliminate exceptions
Diffstat (limited to 'java/src/main/java/com/google/protobuf/ByteString.java')
-rw-r--r-- | java/src/main/java/com/google/protobuf/ByteString.java | 12 |
1 files changed, 12 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 ee2eddb0..04ac7c9a 100644 --- a/java/src/main/java/com/google/protobuf/ByteString.java +++ b/java/src/main/java/com/google/protobuf/ByteString.java @@ -263,6 +263,18 @@ public abstract class ByteString implements Iterable<Byte>, Serializable { } /** + * Encodes {@code text} into a sequence of bytes using the named charset + * and returns the result as a {@code ByteString}. + * + * @param text source string + * @param charset encode using this charset + * @return new {@code ByteString} + */ + public static ByteString copyFrom(String text, Charset charset) { + return new LiteralByteString(text.getBytes(charset)); + } + + /** * Encodes {@code text} into a sequence of UTF-8 bytes and returns the * result as a {@code ByteString}. * |