Files
rr3-apk/decompiled/sources/com/mbridge/msdk/playercommon/exoplayer2/upstream/AssetDataSource.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

134 lines
4.5 KiB
Java

package com.mbridge.msdk.playercommon.exoplayer2.upstream;
import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class AssetDataSource implements DataSource {
private final AssetManager assetManager;
private long bytesRemaining;
private InputStream inputStream;
private final TransferListener<? super AssetDataSource> listener;
private boolean opened;
private Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final Uri getUri() {
return this.uri;
}
public static final class AssetDataSourceException extends IOException {
public AssetDataSourceException(IOException iOException) {
super(iOException);
}
}
public AssetDataSource(Context context) {
this(context, null);
}
public AssetDataSource(Context context, TransferListener<? super AssetDataSource> transferListener) {
this.assetManager = context.getAssets();
this.listener = transferListener;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final long open(DataSpec dataSpec) throws AssetDataSourceException {
try {
Uri uri = dataSpec.uri;
this.uri = uri;
String path = uri.getPath();
if (path.startsWith("/android_asset/")) {
path = path.substring(15);
} else if (path.startsWith("/")) {
path = path.substring(1);
}
InputStream open = this.assetManager.open(path, 1);
this.inputStream = open;
if (open.skip(dataSpec.position) < dataSpec.position) {
throw new EOFException();
}
long j = dataSpec.length;
if (j != -1) {
this.bytesRemaining = j;
} else {
long available = this.inputStream.available();
this.bytesRemaining = available;
if (available == 2147483647L) {
this.bytesRemaining = -1L;
}
}
this.opened = true;
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferStart(this, dataSpec);
}
return this.bytesRemaining;
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final int read(byte[] bArr, int i, int i2) throws AssetDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
if (j != -1) {
try {
i2 = (int) Math.min(j, i2);
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
}
int read = this.inputStream.read(bArr, i, i2);
if (read == -1) {
if (this.bytesRemaining == -1) {
return -1;
}
throw new AssetDataSourceException(new EOFException());
}
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - read;
}
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onBytesTransferred(this, read);
}
return read;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
public final void close() throws AssetDataSourceException {
this.uri = null;
try {
try {
InputStream inputStream = this.inputStream;
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
throw new AssetDataSourceException(e);
}
} finally {
this.inputStream = null;
if (this.opened) {
this.opened = false;
TransferListener<? super AssetDataSource> transferListener = this.listener;
if (transferListener != null) {
transferListener.onTransferEnd(this);
}
}
}
}
}