# 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
public final class ExtractorUtil
```

<br />

*** ** * ** ***

Extractor related utility methods.

## Summary

| ### Public methods |
|---|---|
| `static void` | `@https://checkerframework.org/api/org/checkerframework/dataflow/qual/Pure.html https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#checkContainerInput(boolean,java.lang.String)(boolean expression, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html message)` If `expression` is false, throws a `https://developer.android.com/reference/androidx/media3/common/ParserException#createForMalformedContainer(java.lang.String,java.lang.Throwable)` with the given message. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#getFramesPerEncodedSample(int,java.nio.ByteBuffer)(@https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding, https://developer.android.com/reference/java/nio/ByteBuffer.html buffer)` Returns the number of audio frames per sample for the given encoding. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#getMaximumEncodedRateBytesPerSecond(int)(@https://developer.android.com/reference/androidx/media3/common/C.Encoding int encoding)` Returns the maximum encoded rate for samples of the given encoding. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#peekFullyQuietly(androidx.media3.extractor.ExtractorInput,byte[],int,int,boolean)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, byte[] output, int offset, int length, boolean allowEndOfInput )` Peeks data from `input`, respecting `allowEndOfInput`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#peekToLength(androidx.media3.extractor.ExtractorInput,byte[],int,int)(https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, byte[] target, int offset, int length)` 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. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#readFullyQuietly(androidx.media3.extractor.ExtractorInput,byte[],int,int)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, byte[] output, int offset, int length )` Equivalent to `https://developer.android.com/reference/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. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ExtractorUtil#skipFullyQuietly(androidx.media3.extractor.ExtractorInput,int)(https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, int length)` Equivalent to `https://developer.android.com/reference/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 methods

### checkContainerInput

```
@Pure
public static void checkContainerInput(boolean expression, @Nullable String message)
```

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

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

### getFramesPerEncodedSample

```
public static int getFramesPerEncodedSample(@C.Encoding int encoding, ByteBuffer buffer)
```

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

PCM encodings are not supported.

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

| Returns |
|---|---|
| `int` | 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

```
public static int getMaximumEncodedRateBytesPerSecond(@C.Encoding int encoding)
```

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

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

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

### peekFullyQuietly

```
public static boolean peekFullyQuietly(
    ExtractorInput input,
    byte[] output,
    int offset,
    int length,
    boolean allowEndOfInput
)
```

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/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

```
public static int peekToLength(ExtractorInput input, byte[] target, int offset, int length)
```

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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | The stream input to peek the data from. |
| `byte[] target` | A target array into which data should be written. |
| `int offset` | The offset into the target array at which to write. |
| `int length` | The maximum number of bytes to peek from the input. |

| Returns |
|---|---|
| `int` | The number of bytes peeked. |

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

### readFullyQuietly

```
public static boolean readFullyQuietly(
    ExtractorInput input,
    byte[] output,
    int offset,
    int length
)
```

Equivalent to `https://developer.android.com/reference/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

```
public static boolean skipFullyQuietly(ExtractorInput input, int length)
```

Equivalent to `https://developer.android.com/reference/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` |   |