Package com.google.protobuf
Class Utf8.Processor
- java.lang.Object
-
- com.google.protobuf.Utf8.Processor
-
- Direct Known Subclasses:
Utf8.MobileProcessor,Utf8.ServerProcessor
- Enclosing class:
- Utf8
abstract static class Utf8.Processor extends java.lang.ObjectA processor of UTF-8 strings, providing methods for checking validity and encoding.
-
-
Constructor Summary
Constructors Constructor Description Processor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract java.lang.StringdecodeUtf8(byte[] bytes, int index, int size)Decodes the given byte array slice into aString.(package private) java.lang.StringdecodeUtf8(java.nio.ByteBuffer buffer, int index, int size)Decodes the given portion of theByteBufferinto aString.(package private) java.lang.StringdecodeUtf8NonArrayByteBuffer(java.nio.ByteBuffer buffer, int index, int size)DecodesByteBufferinstances using theByteBufferAPI rather than potentially faster approaches.(package private) intencodedLength(java.lang.String string)(package private) abstract intencodeUtf8(java.lang.String in, byte[] out, int offset, int length)Encodes an input character sequence (in) to UTF-8 in the target array (out).(package private) voidencodeUtf8(java.lang.String in, java.nio.ByteBuffer out)Encodes an input character sequence (in) to UTF-8 in the target buffer (out).protected abstract voidencodeUtf8Internal(java.lang.String in, java.nio.ByteBuffer out)Encodes the input character sequence to a directByteBufferinstance.protected intencodeUtf8Naive(java.lang.String in, byte[] out, int offset, int length)protected voidencodeUtf8Naive(java.lang.String in, java.nio.ByteBuffer out)
-
-
-
Method Detail
-
decodeUtf8
abstract java.lang.String decodeUtf8(byte[] bytes, int index, int size) throws InvalidProtocolBufferExceptionDecodes the given byte array slice into aString.- Throws:
InvalidProtocolBufferException- if the byte array slice is not valid UTF-8
-
decodeUtf8
final java.lang.String decodeUtf8(java.nio.ByteBuffer buffer, int index, int size) throws InvalidProtocolBufferExceptionDecodes the given portion of theByteBufferinto aString.- Throws:
InvalidProtocolBufferException- if the portion of the buffer is not valid UTF-8
-
decodeUtf8NonArrayByteBuffer
final java.lang.String decodeUtf8NonArrayByteBuffer(java.nio.ByteBuffer buffer, int index, int size) throws InvalidProtocolBufferExceptionDecodesByteBufferinstances using theByteBufferAPI rather than potentially faster approaches.- Throws:
InvalidProtocolBufferException
-
encodeUtf8Naive
protected int encodeUtf8Naive(java.lang.String in, byte[] out, int offset, int length)
-
encodeUtf8Naive
protected void encodeUtf8Naive(java.lang.String in, java.nio.ByteBuffer out)
-
encodeUtf8
abstract int encodeUtf8(java.lang.String in, byte[] out, int offset, int length)Encodes an input character sequence (in) to UTF-8 in the target array (out). For a string, this method is functionally identical to
but may be implemented differently for efficiency purposes.byte[] a = string.getBytes(UTF_8); System.arraycopy(a, 0, bytes, offset, a.length); return offset + a.length;Matching
String.getBytes(UTF_8)this replaces unpaired surrogates with a replacement character.To ensure sufficient space in the output buffer, either call
encodedLength(java.lang.String)to compute the exact amount needed, or leave room forUtf8.MAX_BYTES_PER_CHAR * sequence.length(), which is the largest possible number of bytes that any input can be encoded to.- Parameters:
in- the input character sequence to be encodedout- the target arrayoffset- the starting offset inbytesto start writing atlength- the length of thebytes, starting fromoffset- Returns:
- the new offset, equivalent to
offset + Utf8.encodedLength(sequence) - Throws:
java.lang.ArrayIndexOutOfBoundsException- ifsequenceencoded in UTF-8 is longer thanbytes.length - offset
-
encodeUtf8
final void encodeUtf8(java.lang.String in, java.nio.ByteBuffer out)Encodes an input character sequence (in) to UTF-8 in the target buffer (out). Upon returning from this method, theoutposition will point to the position after the last encoded byte. This method requires paired surrogates, and therefore does not support chunking.To ensure sufficient space in the output buffer, either call
encodedLength(java.lang.String)to compute the exact amount needed, or leave room forUtf8.MAX_BYTES_PER_CHAR * in.length(), which is the largest possible number of bytes that any input can be encoded to.- Parameters:
in- the source character sequence to be encodedout- the target buffer- Throws:
java.lang.ArrayIndexOutOfBoundsException- ifinencoded in UTF-8 is longer thanout.remaining()
-
encodeUtf8Internal
protected abstract void encodeUtf8Internal(java.lang.String in, java.nio.ByteBuffer out)Encodes the input character sequence to a directByteBufferinstance.
-
encodedLength
int encodedLength(java.lang.String string)
-
-