- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
186 lines
7.0 KiB
Java
186 lines
7.0 KiB
Java
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
|
|
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.content.res.AssetFileDescriptor;
|
|
import android.net.Uri;
|
|
import java.io.EOFException;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.nio.channels.FileChannel;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public final class ContentDataSource implements DataSource {
|
|
private AssetFileDescriptor assetFileDescriptor;
|
|
private long bytesRemaining;
|
|
private FileInputStream inputStream;
|
|
private final TransferListener<? super ContentDataSource> listener;
|
|
private boolean opened;
|
|
private final ContentResolver resolver;
|
|
private Uri uri;
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final Uri getUri() {
|
|
return this.uri;
|
|
}
|
|
|
|
public static class ContentDataSourceException extends IOException {
|
|
public ContentDataSourceException(IOException iOException) {
|
|
super(iOException);
|
|
}
|
|
}
|
|
|
|
public ContentDataSource(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
public ContentDataSource(Context context, TransferListener<? super ContentDataSource> transferListener) {
|
|
this.resolver = context.getContentResolver();
|
|
this.listener = transferListener;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final long open(DataSpec dataSpec) throws ContentDataSourceException {
|
|
try {
|
|
Uri uri = dataSpec.uri;
|
|
this.uri = uri;
|
|
AssetFileDescriptor openAssetFileDescriptor = this.resolver.openAssetFileDescriptor(uri, "r");
|
|
this.assetFileDescriptor = openAssetFileDescriptor;
|
|
if (openAssetFileDescriptor == null) {
|
|
throw new FileNotFoundException("Could not open file descriptor for: " + this.uri);
|
|
}
|
|
this.inputStream = new FileInputStream(this.assetFileDescriptor.getFileDescriptor());
|
|
long startOffset = this.assetFileDescriptor.getStartOffset();
|
|
long skip = this.inputStream.skip(dataSpec.position + startOffset) - startOffset;
|
|
if (skip != dataSpec.position) {
|
|
throw new EOFException();
|
|
}
|
|
long j = dataSpec.length;
|
|
long j2 = -1;
|
|
if (j != -1) {
|
|
this.bytesRemaining = j;
|
|
} else {
|
|
long length = this.assetFileDescriptor.getLength();
|
|
if (length == -1) {
|
|
FileChannel channel = this.inputStream.getChannel();
|
|
long size = channel.size();
|
|
if (size != 0) {
|
|
j2 = size - channel.position();
|
|
}
|
|
this.bytesRemaining = j2;
|
|
} else {
|
|
this.bytesRemaining = length - skip;
|
|
}
|
|
}
|
|
this.opened = true;
|
|
TransferListener<? super ContentDataSource> transferListener = this.listener;
|
|
if (transferListener != null) {
|
|
transferListener.onTransferStart(this, dataSpec);
|
|
}
|
|
return this.bytesRemaining;
|
|
} catch (IOException e) {
|
|
throw new ContentDataSourceException(e);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final int read(byte[] bArr, int i, int i2) throws ContentDataSourceException {
|
|
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 ContentDataSourceException(e);
|
|
}
|
|
}
|
|
int read = this.inputStream.read(bArr, i, i2);
|
|
if (read == -1) {
|
|
if (this.bytesRemaining == -1) {
|
|
return -1;
|
|
}
|
|
throw new ContentDataSourceException(new EOFException());
|
|
}
|
|
long j2 = this.bytesRemaining;
|
|
if (j2 != -1) {
|
|
this.bytesRemaining = j2 - read;
|
|
}
|
|
TransferListener<? super ContentDataSource> 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 ContentDataSourceException {
|
|
this.uri = null;
|
|
try {
|
|
try {
|
|
FileInputStream fileInputStream = this.inputStream;
|
|
if (fileInputStream != null) {
|
|
fileInputStream.close();
|
|
}
|
|
this.inputStream = null;
|
|
try {
|
|
try {
|
|
AssetFileDescriptor assetFileDescriptor = this.assetFileDescriptor;
|
|
if (assetFileDescriptor != null) {
|
|
assetFileDescriptor.close();
|
|
}
|
|
} catch (IOException e) {
|
|
throw new ContentDataSourceException(e);
|
|
}
|
|
} finally {
|
|
this.assetFileDescriptor = null;
|
|
if (this.opened) {
|
|
this.opened = false;
|
|
TransferListener<? super ContentDataSource> transferListener = this.listener;
|
|
if (transferListener != null) {
|
|
transferListener.onTransferEnd(this);
|
|
}
|
|
}
|
|
}
|
|
} catch (IOException e2) {
|
|
throw new ContentDataSourceException(e2);
|
|
}
|
|
} catch (Throwable th) {
|
|
this.inputStream = null;
|
|
try {
|
|
try {
|
|
AssetFileDescriptor assetFileDescriptor2 = this.assetFileDescriptor;
|
|
if (assetFileDescriptor2 != null) {
|
|
assetFileDescriptor2.close();
|
|
}
|
|
this.assetFileDescriptor = null;
|
|
if (this.opened) {
|
|
this.opened = false;
|
|
TransferListener<? super ContentDataSource> transferListener2 = this.listener;
|
|
if (transferListener2 != null) {
|
|
transferListener2.onTransferEnd(this);
|
|
}
|
|
}
|
|
throw th;
|
|
} catch (IOException e3) {
|
|
throw new ContentDataSourceException(e3);
|
|
}
|
|
} finally {
|
|
this.assetFileDescriptor = null;
|
|
if (this.opened) {
|
|
this.opened = false;
|
|
TransferListener<? super ContentDataSource> transferListener3 = this.listener;
|
|
if (transferListener3 != null) {
|
|
transferListener3.onTransferEnd(this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|