aboutsummaryrefslogtreecommitdiffhomepage
path: root/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
diff options
context:
space:
mode:
authorGravatar Tamir Duberstein <tamird@gmail.com>2015-03-31 20:01:43 -0700
committerGravatar Tamir Duberstein <tamird@gmail.com>2015-04-02 15:06:00 -0700
commit210de285d7ca5e4d4e96867c1c04308d68c5d4dd (patch)
tree983ab06e7e3a37e38a5d6c1768c15f50246df5d3 /javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
parente84893f6768f136cc86e2db69fc1d40ff2be7e3b (diff)
DRY: Use `Charset` statics to eliminate exceptions
Diffstat (limited to 'javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java')
-rw-r--r--javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java12
1 files changed, 4 insertions, 8 deletions
diff --git a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
index 2777f34c..1f0534b1 100644
--- a/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
+++ b/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
@@ -291,7 +291,7 @@ public final class CodedOutputByteBufferNano {
// Unfortunately there does not appear to be any way to tell Java to encode
// UTF-8 directly into our buffer, so we have to let it create its own byte
// array and then copy.
- final byte[] bytes = value.getBytes("UTF-8");
+ final byte[] bytes = value.getBytes(InternalNano.UTF_8);
writeRawVarint32(bytes.length);
writeRawBytes(bytes);
}
@@ -603,13 +603,9 @@ public final class CodedOutputByteBufferNano {
* {@code string} field.
*/
public static int computeStringSizeNoTag(final String value) {
- try {
- final byte[] bytes = value.getBytes("UTF-8");
- return computeRawVarint32Size(bytes.length) +
- bytes.length;
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("UTF-8 not supported.");
- }
+ final byte[] bytes = value.getBytes(InternalNano.UTF_8);
+ return computeRawVarint32Size(bytes.length) +
+ bytes.length;
}
/**