# Class Internal (3.19.4)

    public final class Internal

The classes contained within are used internally by the Protocol Buffer library and generated
message implementations. They are public only because those generated messages do not reside in
the `protobuf` package. Others should not use this class directly.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> Internal

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### EMPTY_BYTE_ARRAY

    public static final byte[] EMPTY_BYTE_ARRAY

An empty byte array constant used in generated code.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |   |

### EMPTY_BYTE_BUFFER

    public static final ByteBuffer EMPTY_BYTE_BUFFER

An empty byte array constant used in generated code.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |   |

### EMPTY_CODED_INPUT_STREAM

    public static final CodedInputStream EMPTY_CODED_INPUT_STREAM

An empty coded input stream constant used in generated code.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.CodedInputStream` |   |

## Static Methods

### \<T\>getDefaultInstance(Class\<T\> clazz)

    public static T <T>getDefaultInstance(Class<T> clazz)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clazz` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

### byteArrayDefaultValue(String bytes)

    public static byte[] byteArrayDefaultValue(String bytes)

Helper called by generated code to construct default values for bytes fields.

This is like [#bytesDefaultValue](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Internal#com_google_protobuf_Internal_bytesDefaultValue_), but returns a byte array.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |   |

### byteBufferDefaultValue(String bytes)

    public static ByteBuffer byteBufferDefaultValue(String bytes)

Helper called by generated code to construct default values for bytes fields.

This is like [#bytesDefaultValue](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Internal#com_google_protobuf_Internal_bytesDefaultValue_), but returns a ByteBuffer.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |   |

### bytesDefaultValue(String bytes)

    public static ByteString bytesDefaultValue(String bytes)

Helper called by generated code to construct default values for bytes fields.

This is a lot like [#stringDefaultValue](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Internal#com_google_protobuf_Internal_stringDefaultValue_), but for bytes fields. In this case we only
need the second of the two hacks -- allowing us to embed raw bytes as a string literal with
ISO-8859-1 encoding.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |   |

### copyByteBuffer(ByteBuffer source)

    public static ByteBuffer copyByteBuffer(ByteBuffer source)

Create a new ByteBuffer and copy all the content of `source` ByteBuffer to the new
ByteBuffer. The new ByteBuffer's limit and capacity will be source.capacity(), and its position
will be 0. Note that the state of `source` ByteBuffer won't be changed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `source` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |   |

### equals(List\<byte\[\]\> a, List\<byte\[\]\> b)

    public static boolean equals(List<byte[]> a, List<byte[]> b)

Helper method for implementing [Message#equals(Object)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_equals_java_lang_Object_) for bytes field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `a` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` |
| `b` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### equalsByteBuffer(ByteBuffer a, ByteBuffer b)

    public static boolean equalsByteBuffer(ByteBuffer a, ByteBuffer b)

Helper method for implementing [Message#equals(Object)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_equals_java_lang_Object_) for bytes field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `a` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |
| `b` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### equalsByteBuffer(List\<ByteBuffer\> a, List\<ByteBuffer\> b)

    public static boolean equalsByteBuffer(List<ByteBuffer> a, List<ByteBuffer> b)

Helper method for implementing [Message#equals(Object)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_equals_java_lang_Object_) for bytes field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `a` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html>` |
| `b` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashBoolean(boolean b)

    public static int hashBoolean(boolean b)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for booleans.
**See Also:** Boolean#hashCode()

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `b` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCode(byte\[\] bytes)

    public static int hashCode(byte[] bytes)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for bytes field.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCode(List\<byte\[\]\> list)

    public static int hashCode(List<byte[]> list)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for bytes field.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `list` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCodeByteBuffer(ByteBuffer bytes)

    public static int hashCodeByteBuffer(ByteBuffer bytes)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for bytes field.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCodeByteBuffer(List\<ByteBuffer\> list)

    public static int hashCodeByteBuffer(List<ByteBuffer> list)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for bytes field.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `list` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashEnum(Internal.EnumLite e)

    public static int hashEnum(Internal.EnumLite e)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for enums.

This is needed because [java.lang.Enum#hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html#hashCode--) is final, but we need to use the
field number as the hash code to ensure compatibility between statically and dynamically
generated enum objects.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `e` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Internal.EnumLite` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashEnumList(List\<? extends Internal.EnumLite\> list)

    public static int hashEnumList(List<? extends Internal.EnumLite> list)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for enum lists.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `list` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<? extends com.google.protobuf.Internal.EnumLite>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashLong(long n)

    public static int hashLong(long n)

Helper method for implementing [Message#hashCode()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Message#com_google_protobuf_Message_hashCode__) for longs.
**See Also:** Long#hashCode()

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `n` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isValidUtf8(byte\[\] byteArray)

    public static boolean isValidUtf8(byte[] byteArray)

Like [#isValidUtf8(ByteString)](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Internal#com_google_protobuf_Internal_isValidUtf8_com_google_protobuf_ByteString_) but for byte arrays.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `byteArray` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isValidUtf8(ByteString byteString)

    public static boolean isValidUtf8(ByteString byteString)

Helper called by generated code to determine if a byte array is a valid UTF-8 encoded string
such that the original bytes can be converted to a String object and then back to a byte array
round tripping the bytes without loss. More precisely, returns `true` whenever:


     Arrays.equals(byteString.toByteArray(),
         new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
     
This method rejects "overlong" byte sequences, as well as 3-byte sequences that would map to
a surrogate character, in accordance with the restricted definition of UTF-8 introduced in
Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has been modified to also
reject "overlong" byte sequences, but currently (2011) still accepts 3-byte surrogate character
byte sequences.

See the Unicode Standard,  

Table 3-6. *UTF-8 Bit Distribution* ,  

Table 3-7. *Well Formed UTF-8 Byte Sequences*.

As of 2011-02, this method simply returns the result of [ByteString#isValidUtf8()](https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString#com_google_protobuf_ByteString_isValidUtf8__).
Calling that method directly is preferred.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `byteString` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` the string to check |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | whether the byte array is round trippable |

### stringDefaultValue(String bytes)

    public static String stringDefaultValue(String bytes)

Helper called by generated code to construct default values for string fields.

The protocol compiler does not actually contain a UTF-8 decoder -- it just pushes
UTF-8-encoded text around without touching it. The one place where this presents a problem is
when generating Java string literals. Unicode characters in the string literal would normally
need to be encoded using a Unicode escape sequence, which would require decoding them. To get
around this, protoc instead embeds the UTF-8 bytes into the generated code and leaves it to the
runtime library to decode them.

It gets worse, though. If protoc just generated a byte array, like: new byte\[\] {0x12, 0x34,
0x56, 0x78} Java actually generates *code* which allocates an array and then fills in each
value. This is much less efficient than just embedding the bytes directly into the bytecode. To
get around this, we need another work-around. String literals are embedded directly, so protoc
actually generates a string literal corresponding to the bytes. The easiest way to do this is
to use the ISO-8859-1 character set, which corresponds to the first 256 characters of the
Unicode range. Protoc can then use good old CEscape to generate the string.

So we have a string literal which represents a set of bytes which represents another string.
This function -- stringDefaultValue -- converts from the generated string to the string we
actually want. The generated code calls this automatically.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### toByteArray(String value)

    public static byte[] toByteArray(String value)

Helper method to get the UTF-8 bytes of a string.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |   |

### toStringUtf8(byte\[\] bytes)

    public static String toStringUtf8(byte[] bytes)

Helper method to convert a byte array to a string using UTF-8 encoding.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |