# ParsableByteArray

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/ParsableByteArray.java+class:androidx.media3.common.util.ParsableByteArray)

*** ** * ** ***


```
@UnstableApi
@CheckReturnValue
public final class ParsableByteArray
```

<br />

*** ** * ** ***

Wraps a byte array, providing a set of methods for parsing data from it. Numerical values are parsed with the assumption that their constituent bytes are in big endian order.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#INVALID_CODE_POINT() = 1114112` A value that is outside the valid range of unicode code points. |

| ### Public fields |
|---|---|
| `byte[]` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#data()` |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#position()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ParsableByteArray()()` Creates a new instance that initially has no backing data. |
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ParsableByteArray(byte[])(byte[] data)` Creates a new instance wrapping `data`, and sets the limit to `data.length`. |
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ParsableByteArray(int)(int limit)` Creates a new instance with `limit` bytes and sets the limit. |
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ParsableByteArray(byte[],int)(byte[] data, int limit)` Creates a new instance that wraps an existing array. |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#bytesLeft()()` Returns the number of bytes yet to be read. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#capacity()()` Returns the capacity of the array, which may be larger than the limit. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ensureCapacity(int)(int requiredCapacity)` Ensures the backing array is at least `requiredCapacity` long. |
| `byte[]` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getData()()` Returns the underlying array. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()()` Returns the current offset in the array, in bytes. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#isCharsetSupported(java.nio.charset.Charset)(https://developer.android.com/reference/java/nio/charset/Charset.html charset)` Returns whether the provided `https://developer.android.com/reference/java/nio/charset/Charset.html` is supported when passed to methods like `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar(java.nio.charset.Charset)` and `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLine(java.nio.charset.Charset)`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#limit()()` Returns the limit. |
| `char` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar()()` Peeks at the next two bytes and interprets them as a big-endian char. |
| `char` | `[peekChar](https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar(java.nio.charset.Charset))(https://developer.android.com/reference/java/nio/charset/Charset.html charset)` **This method is deprecated.** Either use `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar()` to peek the next two bytes (big-endian) or `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekCodePoint(java.nio.charset.Charset)` to peek in a `https://developer.android.com/reference/java/nio/charset/Charset.html`-aware way. <br /> |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekCodePoint(java.nio.charset.Charset)(https://developer.android.com/reference/java/nio/charset/Charset.html charset)` Peeks at the code point starting at `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` as interpreted by `charset`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekInt()()` Peeks the next four bytes as a signed value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekUnsignedByte()()` Peeks at the next byte as an unsigned value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekUnsignedInt24()()` Peeks the next three bytes as an unsigned value. |
| `byte` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readByte()()` Reads the next byte as a signed value. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readBytes(androidx.media3.common.util.ParsableBitArray,int)(https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray bitArray, int length)` Reads the next `length` bytes into `bitArray`, and resets the position of ` bitArray` to zero. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readBytes(java.nio.ByteBuffer,int)(https://developer.android.com/reference/java/nio/ByteBuffer.html buffer, int length)` Reads the next `length` bytes into `buffer`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readBytes(byte[],int,int)(byte[] buffer, int offset, int length)` Reads the next `length` bytes into `buffer` at `offset`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readDelimiterTerminatedString(char)(char delimiter)` Reads up to the next delimiter byte (or the limit) as UTF-8 characters. |
| `double` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readDouble()()` Reads the next eight bytes as a 64-bit floating point value. |
| `float` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readFloat()()` Reads the next four bytes as a 32-bit floating point value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readInt()()` Reads the next four bytes as a signed value |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readInt24()()` Reads the next three bytes as a signed value. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLine()()` Reads a line of text in UTF-8. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLine(java.nio.charset.Charset)(https://developer.android.com/reference/java/nio/charset/Charset.html charset)` Reads a line of text in `charset`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianInt()()` Reads the next four bytes as a signed value in little endian order. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianInt24()()` Reads the next three bytes as a signed value in little endian order. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianLong()()` Reads the next eight bytes as a signed value in little endian order. |
| `short` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianShort()()` Reads the next two bytes as a signed value. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianUnsignedInt()()` Reads the next four bytes as an unsigned value in little endian order. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianUnsignedInt24()()` Reads the next three bytes as an unsigned value in little endian order. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianUnsignedIntToInt()()` Reads the next four bytes as a little endian unsigned integer into an integer, if the top bit is a zero. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLittleEndianUnsignedShort()()` Reads the next two bytes as an unsigned value. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLong()()` Reads the next eight bytes as a signed value. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readNullTerminatedString()()` Reads up to the next NUL byte (or the limit) as UTF-8 characters. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readNullTerminatedString(int)(int length)` Reads the next `length` bytes as UTF-8 characters. |
| `short` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readShort()()` Reads the next two bytes as a signed value. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readString(int)(int length)` Reads the next `length` bytes as UTF-8 characters. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readString(int,java.nio.charset.Charset)(int length, https://developer.android.com/reference/java/nio/charset/Charset.html charset)` Reads the next `length` bytes as characters in the specified `https://developer.android.com/reference/java/nio/charset/Charset.html`. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readSynchSafeInt()()` Reads a Synchsafe integer. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedByte()()` Reads the next byte as an unsigned value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedFixedPoint1616()()` Reads the next four bytes, returning the integer portion of the fixed point 16.16 integer. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedInt()()` Reads the next four bytes as an unsigned value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedInt24()()` Reads the next three bytes as an unsigned value. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedIntToInt()()` Reads the next four bytes as an unsigned integer into an integer, if the top bit is a zero. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedLeb128ToInt()()` Reads an unsigned variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value into an int. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedLeb128ToLong()()` Reads an unsigned variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value into a long. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedLongToLong()()` Reads the next eight bytes as an unsigned long into a long, if the top bit is a zero. |
| `int` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUnsignedShort()()` Reads the next two bytes as an unsigned value. |
| `long` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUtf8EncodedLong()()` Reads a long value encoded by UTF-8 encoding |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/nio/charset/Charset.html` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readUtfCharsetFromBom()()` Reads a UTF byte order mark (BOM) and returns the UTF `https://developer.android.com/reference/java/nio/charset/Charset.html` it represents. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#reset(byte[])(byte[] data)` Updates the instance to wrap `data`, and resets the position to zero and the limit to `data.length`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#reset(int)(int limit)` Resets the position to zero and the limit to the specified value. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#reset(byte[],int)(byte[] data, int limit)` Updates the instance to wrap `data`, and resets the position to zero. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#setLimit(int)(int limit)` Sets the limit. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#setPosition(int)(int position)` Sets the reading offset in the array. |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting [setShouldEnforceLimitOnLegacyMethods](https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#setShouldEnforceLimitOnLegacyMethods(java.lang.Boolean))(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Boolean.html enforceLimit)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/common/Flags#enableFlag(int)` or `https://developer.android.com/reference/androidx/media3/common/Flags#disableFlag(int)` with `https://developer.android.com/reference/androidx/media3/common/Flags#FLAG_ENFORCE_PARSABLE_BYTE_ARRAY_LIMIT()` instead. <br /> |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#skipBytes(int)(int bytes)` Moves the reading offset by `bytes`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#skipLeb128()()` Skips a variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value. |

## Constants

### INVALID_CODE_POINT

```
public static final int INVALID_CODE_POINT = 1114112
```

A value that is outside the valid range of unicode code points.

## Public fields

### data

```
public byte[] data
```

### position

```
public int position
```

## Public constructors

### ParsableByteArray

```
public ParsableByteArray()
```

Creates a new instance that initially has no backing data.

### ParsableByteArray

```
public ParsableByteArray(byte[] data)
```

Creates a new instance wrapping `data`, and sets the limit to `data.length`.

| Parameters |
|---|---|
| `byte[] data` | The array to wrap. |

### ParsableByteArray

```
public ParsableByteArray(int limit)
```

Creates a new instance with `limit` bytes and sets the limit.

| Parameters |
|---|---|
| `int limit` | The limit to set. |

### ParsableByteArray

```
public ParsableByteArray(byte[] data, int limit)
```

Creates a new instance that wraps an existing array.

| Parameters |
|---|---|
| `byte[] data` | The data to wrap. |
| `int limit` | The limit to set. |

## Public methods

### bytesLeft

```
public int bytesLeft()
```

Returns the number of bytes yet to be read.

### capacity

```
public int capacity()
```

Returns the capacity of the array, which may be larger than the limit.

### ensureCapacity

```
public void ensureCapacity(int requiredCapacity)
```

Ensures the backing array is at least `requiredCapacity` long.

`https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()`, `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#limit()`, and all data in the underlying array (including that beyond `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#limit()`) are preserved.

This might replace or wipe the `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getData()`, potentially invalidating any local references.

### getData

```
public byte[] getData()
```

Returns the underlying array.

Changes to this array are reflected in the results of the `read...()` methods.

This reference must be assumed to become invalid when `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#reset(int)` or `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#ensureCapacity(int)` are called (because the array might get reallocated).

### getPosition

```
public int getPosition()
```

Returns the current offset in the array, in bytes.

### isCharsetSupported

```
public static boolean isCharsetSupported(Charset charset)
```

Returns whether the provided `https://developer.android.com/reference/java/nio/charset/Charset.html` is supported when passed to methods like `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar(java.nio.charset.Charset)` and `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLine(java.nio.charset.Charset)`.

### limit

```
public int limit()
```

Returns the limit.

### peekChar

```
public char peekChar()
```

Peeks at the next two bytes and interprets them as a big-endian char.

### peekChar

```
public char [peekChar](https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar(java.nio.charset.Charset))(Charset charset)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Either use `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekChar()` to peek the next two bytes (big-endian) or `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#peekCodePoint(java.nio.charset.Charset)` to peek in a `https://developer.android.com/reference/java/nio/charset/Charset.html`-aware way.

### peekCodePoint

```
public int peekCodePoint(Charset charset)
```

Peeks at the code point starting at `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` as interpreted by `charset`.

The exact behaviour depends on `charset`:

- US_ASCII: Returns the byte at `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` if it's valid ASCII (less than `0x80`), otherwise returns `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#INVALID_CODE_POINT()`.
- UTF-8: If `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` is the start of a UTF-8 code unit the whole unit is decoded and returned. Otherwise `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#INVALID_CODE_POINT()` is returned.
- UTF-16 (all endian-nesses):
  - If `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` is at the start of a `https://developer.android.com/reference/java/lang/Character.html#isHighSurrogate(char)` code unit and the following two bytes are a `https://developer.android.com/reference/java/lang/Character.html#isLowSurrogate(char)` low surrogate} code unit, the `https://developer.android.com/reference/java/lang/Character.html#toCodePoint(char, char)` is returned.
  - Otherwise the single code unit starting at `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` is returned directly.
  - UTF-16 has no support for byte-level synchronization, so if `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` is not aligned with the start of a UTF-16 code unit then the result is undefined.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if charset is not supported. Only US_ASCII, UTF-8, UTF-16, UTF-16BE, and UTF-16LE are supported. |
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException.html` | if `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#bytesLeft()` doesn't allow reading the smallest code unit in `charset` (1 byte for ASCII and UTF-8, 2 bytes for UTF-16). |

### peekInt

```
public int peekInt()
```

Peeks the next four bytes as a signed value.

### peekUnsignedByte

```
public int peekUnsignedByte()
```

Peeks at the next byte as an unsigned value.

### peekUnsignedInt24

```
public int peekUnsignedInt24()
```

Peeks the next three bytes as an unsigned value.

### readByte

```
public byte readByte()
```

Reads the next byte as a signed value.

### readBytes

```
public void readBytes(ParsableBitArray bitArray, int length)
```

Reads the next `length` bytes into `bitArray`, and resets the position of `
bitArray` to zero.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray bitArray` | The `https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray` into which the bytes should be read. |
| `int length` | The number of bytes to write. |

### readBytes

```
public void readBytes(ByteBuffer buffer, int length)
```

Reads the next `length` bytes into `buffer`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` into which the read data should be written. |
| `int length` | The number of bytes to read. |

| See also |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html#put(byte[], int, int)` |   |

### readBytes

```
public void readBytes(byte[] buffer, int offset, int length)
```

Reads the next `length` bytes into `buffer` at `offset`.

| Parameters |
|---|---|
| `byte[] buffer` | The array into which the read data should be written. |
| `int offset` | The offset in `buffer` at which the read data should be written. |
| `int length` | The number of bytes to read. |

| See also |
|---|---|
| `https://developer.android.com/reference/java/lang/System.html#arraycopy(java.lang.Object, int, java.lang.Object, int, int)` |   |

### readDelimiterTerminatedString

```
public @Nullable String readDelimiterTerminatedString(char delimiter)
```

Reads up to the next delimiter byte (or the limit) as UTF-8 characters.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | The string not including any terminating delimiter byte, or null if the end of the data has already been reached. |

### readDouble

```
public double readDouble()
```

Reads the next eight bytes as a 64-bit floating point value.

### readFloat

```
public float readFloat()
```

Reads the next four bytes as a 32-bit floating point value.

### readInt

```
public int readInt()
```

Reads the next four bytes as a signed value

### readInt24

```
public int readInt24()
```

Reads the next three bytes as a signed value.

### readLine

```
public @Nullable String readLine()
```

Reads a line of text in UTF-8.

Equivalent to passing `https://developer.android.com/reference/java/nio/charset/StandardCharsets.html#UTF_8` to `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#readLine(java.nio.charset.Charset)`.

### readLine

```
public @Nullable String readLine(Charset charset)
```

Reads a line of text in `charset`.

A line is considered to be terminated by any one of a carriage return ('\\r'), a line feed ('\\n'), or a carriage return followed immediately by a line feed ('\\r\\n'). This method discards leading UTF byte order marks (BOM), if present.

The `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` is advanced to start of the next line (i.e. any line terminators are skipped).

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/nio/charset/Charset.html charset` | The charset used to interpret the bytes as a `https://developer.android.com/reference/java/lang/String.html`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | The line not including any line-termination characters, or null if the end of the data has already been reached. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if charset is not supported. Only US_ASCII, UTF-8, UTF-16, UTF-16BE, and UTF-16LE are supported. |

### readLittleEndianInt

```
public int readLittleEndianInt()
```

Reads the next four bytes as a signed value in little endian order.

### readLittleEndianInt24

```
public int readLittleEndianInt24()
```

Reads the next three bytes as a signed value in little endian order.

### readLittleEndianLong

```
public long readLittleEndianLong()
```

Reads the next eight bytes as a signed value in little endian order.

### readLittleEndianShort

```
public short readLittleEndianShort()
```

Reads the next two bytes as a signed value.

### readLittleEndianUnsignedInt

```
public long readLittleEndianUnsignedInt()
```

Reads the next four bytes as an unsigned value in little endian order.

### readLittleEndianUnsignedInt24

```
public int readLittleEndianUnsignedInt24()
```

Reads the next three bytes as an unsigned value in little endian order.

### readLittleEndianUnsignedIntToInt

```
public int readLittleEndianUnsignedIntToInt()
```

Reads the next four bytes as a little endian unsigned integer into an integer, if the top bit is a zero.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | Thrown if the top bit of the input data is set. |

### readLittleEndianUnsignedShort

```
public int readLittleEndianUnsignedShort()
```

Reads the next two bytes as an unsigned value.

### readLong

```
public long readLong()
```

Reads the next eight bytes as a signed value.

### readNullTerminatedString

```
public @Nullable String readNullTerminatedString()
```

Reads up to the next NUL byte (or the limit) as UTF-8 characters.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html` | The string not including any terminating NUL byte, or null if the end of the data has already been reached. |

### readNullTerminatedString

```
public String readNullTerminatedString(int length)
```

Reads the next `length` bytes as UTF-8 characters. A terminating NUL byte is discarded, if present.

| Parameters |
|---|---|
| `int length` | The number of bytes to read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The string, not including any terminating NUL byte. |

### readShort

```
public short readShort()
```

Reads the next two bytes as a signed value.

### readString

```
public String readString(int length)
```

Reads the next `length` bytes as UTF-8 characters.

| Parameters |
|---|---|
| `int length` | The number of bytes to read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The string encoded by the bytes. |

### readString

```
public String readString(int length, Charset charset)
```

Reads the next `length` bytes as characters in the specified `https://developer.android.com/reference/java/nio/charset/Charset.html`.

| Parameters |
|---|---|
| `int length` | The number of bytes to read. |
| `https://developer.android.com/reference/java/nio/charset/Charset.html charset` | The character set of the encoded characters. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The string encoded by the bytes in the specified character set. |

### readSynchSafeInt

```
public int readSynchSafeInt()
```

Reads a Synchsafe integer.

Synchsafe integers keep the highest bit of every byte zeroed. A 32 bit synchsafe integer can store 28 bits of information.

| Returns |
|---|---|
| `int` | The parsed value. |

### readUnsignedByte

```
public int readUnsignedByte()
```

Reads the next byte as an unsigned value.

### readUnsignedFixedPoint1616

```
public int readUnsignedFixedPoint1616()
```

Reads the next four bytes, returning the integer portion of the fixed point 16.16 integer.

### readUnsignedInt

```
public long readUnsignedInt()
```

Reads the next four bytes as an unsigned value.

### readUnsignedInt24

```
public int readUnsignedInt24()
```

Reads the next three bytes as an unsigned value.

### readUnsignedIntToInt

```
public int readUnsignedIntToInt()
```

Reads the next four bytes as an unsigned integer into an integer, if the top bit is a zero.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | Thrown if the top bit of the input data is set. |

### readUnsignedLeb128ToInt

```
public int readUnsignedLeb128ToInt()
```

Reads an unsigned variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value into an int.

| Returns |
|---|---|
| `int` | integer value |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the read value is greater than `https://developer.android.com/reference/java/lang/Integer.html#MAX_VALUE` or less than `https://developer.android.com/reference/java/lang/Integer.html#MIN_VALUE` |

### readUnsignedLeb128ToLong

```
public long readUnsignedLeb128ToLong()
```

Reads an unsigned variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value into a long.

| Returns |
|---|---|
| `long` | long value |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the byte to be read is over the limit of the parsable byte array |

### readUnsignedLongToLong

```
public long readUnsignedLongToLong()
```

Reads the next eight bytes as an unsigned long into a long, if the top bit is a zero.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | Thrown if the top bit of the input data is set. |

### readUnsignedShort

```
public int readUnsignedShort()
```

Reads the next two bytes as an unsigned value.

### readUtf8EncodedLong

```
public long readUtf8EncodedLong()
```

Reads a long value encoded by UTF-8 encoding

| Returns |
|---|---|
| `long` | Decoded long value |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException.html` | if there is a problem with decoding |

### readUtfCharsetFromBom

```
public @Nullable Charset readUtfCharsetFromBom()
```

Reads a UTF byte order mark (BOM) and returns the UTF `https://developer.android.com/reference/java/nio/charset/Charset.html` it represents. Returns `null` without advancing `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` if no BOM is found.

### reset

```
public void reset(byte[] data)
```

Updates the instance to wrap `data`, and resets the position to zero and the limit to `data.length`.

| Parameters |
|---|---|
| `byte[] data` | The array to wrap. |

### reset

```
public void reset(int limit)
```

Resets the position to zero and the limit to the specified value. This might replace or wipe the `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getData()`, potentially invalidating any local references.

| Parameters |
|---|---|
| `int limit` | The limit to set. |

### reset

```
public void reset(byte[] data, int limit)
```

Updates the instance to wrap `data`, and resets the position to zero.

| Parameters |
|---|---|
| `byte[] data` | The array to wrap. |
| `int limit` | The limit to set. |

### setLimit

```
public void setLimit(int limit)
```

Sets the limit.

| Parameters |
|---|---|
| `int limit` | The limit to set. |

### setPosition

```
public void setPosition(int position)
```

Sets the reading offset in the array.

| Parameters |
|---|---|
| `int position` | Byte offset in the array from which to read. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | Thrown if the new position is neither in nor at the end of the array. |

### setShouldEnforceLimitOnLegacyMethods

```
@VisibleForTesting
public static void [setShouldEnforceLimitOnLegacyMethods](https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#setShouldEnforceLimitOnLegacyMethods(java.lang.Boolean))(@Nullable Boolean enforceLimit)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/common/Flags#enableFlag(int)` or `https://developer.android.com/reference/androidx/media3/common/Flags#disableFlag(int)` with `https://developer.android.com/reference/androidx/media3/common/Flags#FLAG_ENFORCE_PARSABLE_BYTE_ARRAY_LIMIT()` instead.

Sets whether all read/peek methods should enforce that `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getPosition()` never exceeds `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#limit()`.

Setting this to `true` can help catch cases of accidentally reading beyond `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#limit()` but still within the bounds of the underlying `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray#getData()`.

Some (newer) methods will always enforce the invariant, even when this is set to `
false`.

Defaults to `null`, which means a default value is used (which may change in a later release).

### skipBytes

```
public void skipBytes(int bytes)
```

Moves the reading offset by `bytes`.

| Parameters |
|---|---|
| `int bytes` | The number of bytes to skip. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | Thrown if the new position is neither in nor at the end of the array. |

### skipLeb128

```
public void skipLeb128()
```

Skips a variable-length [LEB128](https://en.wikipedia.org/wiki/LEB128) value.