# ExtractorUtil

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

*** ** * ** ***


```
@UnstableApi
class ExtractorUtil
```

<br />

*** ** * ** ***

Extractor related utility methods.

## Summary

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#checkContainerInput(boolean,java.lang.String)(expression: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` If `expression` is false, throws a `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException#createForMalformedContainer(java.lang.String,java.lang.Throwable)` with the given message. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#getFramesPerEncodedSample(int,java.nio.ByteBuffer)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!)` Returns the number of audio frames per sample for the given encoding. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#getMaximumEncodedRateBytesPerSecond(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the maximum encoded rate for samples of the given encoding. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#peekFullyQuietly(androidx.media3.extractor.ExtractorInput,byte[],int,int,boolean)( input: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput!, output: 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, allowEndOfInput: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Peeks data from `input`, respecting `allowEndOfInput`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#peekToLength(androidx.media3.extractor.ExtractorInput,byte[],int,int)( input: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput!, target: 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 )` Peeks `length` bytes from the input peek position, or all the bytes to the end of the input if there was less than `length` bytes left. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#readFullyQuietly(androidx.media3.extractor.ExtractorInput,byte[],int,int)( input: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput!, output: 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 )` Equivalent to `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#readFully(byte[],int,int)` except that it returns ` false` instead of throwing an `https://developer.android.com/reference/java/io/EOFException.html` if the end of input is encountered without having fully satisfied the read. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorUtil#skipFullyQuietly(androidx.media3.extractor.ExtractorInput,int)(input: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput!, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Equivalent to `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#skipFully(int)` except that it returns `false` instead of throwing an `https://developer.android.com/reference/java/io/EOFException.html` if the end of input is encountered without having fully satisfied the skip. |

## Public functions

### checkContainerInput

```
@Pure
java-static fun checkContainerInput(expression: Boolean, message: String?): Unit
```

If `expression` is false, throws a `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException#createForMalformedContainer(java.lang.String,java.lang.Throwable)` with the given message. Otherwise, does nothing.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` |   |

### getFramesPerEncodedSample

```
java-static fun getFramesPerEncodedSample(@C.Encoding encoding: Int, buffer: ByteBuffer!): Int
```

Returns the number of audio frames per sample for the given encoding.

PCM encodings are not supported.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding`. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` containing the encoded sample. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of audio frames per sample for the given encoding. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | If the sample data is invalid. |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the encoding is not an encoded audio format, such as a PCM encoding. |

### getMaximumEncodedRateBytesPerSecond

```
java-static fun getMaximumEncodedRateBytesPerSecond(@C.Encoding encoding: Int): Int
```

Returns the maximum encoded rate for samples of the given encoding.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/C.Encoding`. Value is one of the following: - `Format.NO_VALUE` <br /> |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The maximum encoded rate for this encoding in bytes per second, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#RATE_UNSET_INT()` if unknown. |

### peekFullyQuietly

```
java-static fun peekFullyQuietly(
    input: ExtractorInput!,
    output: ByteArray<Byte>!,
    offset: Int,
    length: Int,
    allowEndOfInput: Boolean
): Boolean
```

Peeks data from `input`, respecting `allowEndOfInput`. Returns true if the peek is successful.

If `allowEndOfInput=false` then encountering the end of the input (whether before or after reading some data) will throw `https://developer.android.com/reference/java/io/EOFException.html`.

If `allowEndOfInput=true` then encountering the end of the input (even after reading some data) will return `false`.

This is slightly different to the behaviour of `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#peekFully(byte[],int,int,boolean)`, where `allowEndOfInput=true` only returns false (and suppresses the exception) if the end of the input is reached before reading any data.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### peekToLength

```
java-static fun peekToLength(
    input: ExtractorInput!,
    target: ByteArray<Byte>!,
    offset: Int,
    length: Int
): Int
```

Peeks `length` bytes from the input peek position, or all the bytes to the end of the input if there was less than `length` bytes left.

If an exception is thrown, there is no guarantee on the peek position.

| Parameters |
|---|---|
| `input: https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput!` | The stream input to peek the data from. |
| `target: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | A target array into which data should be written. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset into the target array at which to write. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The maximum number of bytes to peek from the input. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes peeked. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs peeking from the input. |

### readFullyQuietly

```
java-static fun readFullyQuietly(
    input: ExtractorInput!,
    output: ByteArray<Byte>!,
    offset: Int,
    length: Int
): Boolean
```

Equivalent to `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#readFully(byte[],int,int)` except that it returns `
false` instead of throwing an `https://developer.android.com/reference/java/io/EOFException.html` if the end of input is encountered without having fully satisfied the read.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### skipFullyQuietly

```
java-static fun skipFullyQuietly(input: ExtractorInput!, length: Int): Boolean
```

Equivalent to `https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput#skipFully(int)` except that it returns `false` instead of throwing an `https://developer.android.com/reference/java/io/EOFException.html` if the end of input is encountered without having fully satisfied the skip.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |