# ParsableBitArray

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/ParsableBitArray.java+class:androidx.media3.common.util.ParsableBitArray)

*** ** * ** ***


```
@UnstableApi
@CheckReturnValue
class ParsableBitArray
```

<br />

*** ** * ** ***

Wraps a byte array, providing methods that allow it to be read as a bitstream.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#ParsableBitArray()()` Creates a new instance that initially has no backing data. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#ParsableBitArray(byte[])(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Creates a new instance that wraps an existing array. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#ParsableBitArray(byte[],int)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, limit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Creates a new instance that wraps an existing array. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#bitsLeft()()` Returns the number of bits yet to be read. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#byteAlign()()` Aligns the position to the next byte boundary. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#getBytePosition()()` Returns the current byte offset. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#getPosition()()` Returns the current bit offset. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#putInt(int,int)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Overwrites `numBits` from this array using the `numBits` least significant bits from `value`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBit()()` Reads a single bit. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBits(int)(numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads up to 32 bits. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBits(byte[],int,int)(buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads `numBits` bits into `buffer`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBitsToLong(int)(numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads up to 64 bits. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBytes(byte[],int,int)(buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads the next `length` bytes into `buffer`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBytesAsString(int)(length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads the next `length` bytes as a UTF-8 string. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#readBytesAsString(int,java.nio.charset.Charset)(length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, charset: https://developer.android.com/reference/java/nio/charset/Charset.html!)` Reads the next `length` bytes as a string encoded in `https://developer.android.com/reference/java/nio/charset/Charset.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#reset(byte[])(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Updates the instance to wrap `data`, and resets the position to zero. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#reset(androidx.media3.common.util.ParsableByteArray)(parsableByteArray: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!)` Sets this instance's data, position and limit to match the provided `parsableByteArray`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#reset(byte[],int)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, limit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Updates the instance to wrap `data`, and resets the position to zero. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#setPosition(int)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the current bit offset. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#skipBit()()` Skips a single bit. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#skipBits(int)(numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Skips bits and moves current reading position forward. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#skipBytes(int)(length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Skips the next `length` bytes. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#data()` |

## Public constructors

### ParsableBitArray

```
ParsableBitArray()
```

Creates a new instance that initially has no backing data.

### ParsableBitArray

```
ParsableBitArray(data: ByteArray<Byte>!)
```

Creates a new instance that wraps an existing array.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The data to wrap. |

### ParsableBitArray

```
ParsableBitArray(data: ByteArray<Byte>!, limit: Int)
```

Creates a new instance that wraps an existing array.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The data to wrap. |
| `limit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The limit in bytes. |

## Public functions

### bitsLeft

```
fun bitsLeft(): Int
```

Returns the number of bits yet to be read.

### byteAlign

```
fun byteAlign(): Unit
```

Aligns the position to the next byte boundary. Does nothing if the position is already aligned.

### getBytePosition

```
fun getBytePosition(): Int
```

Returns the current byte offset. Must only be called when the position is byte aligned.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the position isn't byte aligned. |

### getPosition

```
fun getPosition(): Int
```

Returns the current bit offset.

### putInt

```
fun putInt(value: Int, numBits: Int): Unit
```

Overwrites `numBits` from this array using the `numBits` least significant bits from `value`. Bits are written in order from most significant to least significant. The read position is advanced by `numBits`.

| Parameters |
|---|---|
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The integer whose `numBits` least significant bits are written into `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray#data()`. |
| `numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bits to write. |

### readBit

```
fun readBit(): Boolean
```

Reads a single bit.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the bit is set. |

### readBits

```
fun readBits(numBits: Int): Int
```

Reads up to 32 bits.

| Parameters |
|---|---|
| `numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bits to read. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | An integer whose bottom `numBits` bits hold the read data. |

### readBits

```
fun readBits(buffer: ByteArray<Byte>!, offset: Int, numBits: Int): Unit
```

Reads `numBits` bits into `buffer`.

| Parameters |
|---|---|
| `buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The array into which the read data should be written. The trailing `numBits % 8` bits are written into the most significant bits of the last modified `buffer` byte. The remaining ones are unmodified. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset in `buffer` at which the read data should be written. |
| `numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bits to read. |

### readBitsToLong

```
fun readBitsToLong(numBits: Int): Long
```

Reads up to 64 bits.

| Parameters |
|---|---|
| `numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bits to read. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | A long whose bottom `numBits` bits hold the read data. |

### readBytes

```
fun readBytes(buffer: ByteArray<Byte>!, offset: Int, length: Int): Unit
```

Reads the next `length` bytes into `buffer`. Must only be called when the position is byte aligned.

| Parameters |
|---|---|
| `buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The array into which the read data should be written. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset in `buffer` at which the read data should be written. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to read. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the position isn't byte aligned. |

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

### readBytesAsString

```
fun readBytesAsString(length: Int): String!
```

Reads the next `length` bytes as a UTF-8 string. Must only be called when the position is byte aligned.

| Parameters |
|---|---|
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to read. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The string encoded by the bytes in UTF-8. |

### readBytesAsString

```
fun readBytesAsString(length: Int, charset: Charset!): String!
```

Reads the next `length` bytes as a string encoded in `https://developer.android.com/reference/java/nio/charset/Charset.html`. Must only be called when the position is byte aligned.

| Parameters |
|---|---|
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to read. |
| `charset: https://developer.android.com/reference/java/nio/charset/Charset.html!` | The character set of the encoded characters. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The string encoded by the bytes in the specified character set. |

### reset

```
fun reset(data: ByteArray<Byte>!): Unit
```

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

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The array to wrap. |

### reset

```
fun reset(parsableByteArray: ParsableByteArray!): Unit
```

Sets this instance's data, position and limit to match the provided `parsableByteArray`. Any modifications to the underlying data array will be visible in both instances

| Parameters |
|---|---|
| `parsableByteArray: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray`. |

### reset

```
fun reset(data: ByteArray<Byte>!, limit: Int): Unit
```

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

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The array to wrap. |
| `limit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The limit in bytes. |

### setPosition

```
fun setPosition(position: Int): Unit
```

Sets the current bit offset.

| Parameters |
|---|---|
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The position to set. |

### skipBit

```
fun skipBit(): Unit
```

Skips a single bit.

### skipBits

```
fun skipBits(numBits: Int): Unit
```

Skips bits and moves current reading position forward.

| Parameters |
|---|---|
| `numBits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bits to skip. |

### skipBytes

```
fun skipBytes(length: Int): Unit
```

Skips the next `length` bytes. Must only be called when the position is byte aligned.

| Parameters |
|---|---|
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to read. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the position isn't byte aligned. |

## Public properties

### data

```
val data: Array<Byte>!
```