mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 01:22:33 -06:00
93 lines
3.2 KiB
Java
93 lines
3.2 KiB
Java
package com.google.android.exoplayer2.upstream;
|
|
|
|
import android.net.Uri;
|
|
import android.util.Base64;
|
|
import com.google.android.exoplayer2.ParserException;
|
|
import com.google.android.exoplayer2.util.Assertions;
|
|
import com.google.android.exoplayer2.util.Util;
|
|
import com.google.common.base.Charsets;
|
|
import java.io.IOException;
|
|
import java.net.URLDecoder;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class DataSchemeDataSource extends BaseDataSource {
|
|
public static final String SCHEME_DATA = "data";
|
|
private int bytesRemaining;
|
|
private byte[] data;
|
|
private DataSpec dataSpec;
|
|
private int readPosition;
|
|
|
|
public DataSchemeDataSource() {
|
|
super(false);
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public long open(DataSpec dataSpec) throws IOException {
|
|
transferInitializing(dataSpec);
|
|
this.dataSpec = dataSpec;
|
|
Uri uri = dataSpec.uri;
|
|
String scheme = uri.getScheme();
|
|
Assertions.checkArgument("data".equals(scheme), "Unsupported scheme: " + scheme);
|
|
String[] split = Util.split(uri.getSchemeSpecificPart(), ",");
|
|
if (split.length != 2) {
|
|
throw ParserException.createForMalformedDataOfUnknownType("Unexpected URI format: " + uri, null);
|
|
}
|
|
String str = split[1];
|
|
if (split[0].contains(";base64")) {
|
|
try {
|
|
this.data = Base64.decode(str, 0);
|
|
} catch (IllegalArgumentException e) {
|
|
throw ParserException.createForMalformedDataOfUnknownType("Error while parsing Base64 encoded string: " + str, e);
|
|
}
|
|
} else {
|
|
this.data = Util.getUtf8Bytes(URLDecoder.decode(str, Charsets.US_ASCII.name()));
|
|
}
|
|
if (dataSpec.position > this.data.length) {
|
|
this.data = null;
|
|
throw new DataSourceException(2008);
|
|
}
|
|
int i = (int) dataSpec.position;
|
|
this.readPosition = i;
|
|
this.bytesRemaining = this.data.length - i;
|
|
if (dataSpec.length != -1) {
|
|
this.bytesRemaining = (int) Math.min(this.bytesRemaining, dataSpec.length);
|
|
}
|
|
transferStarted(dataSpec);
|
|
return dataSpec.length != -1 ? dataSpec.length : this.bytesRemaining;
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataReader
|
|
public int read(byte[] bArr, int i, int i2) {
|
|
if (i2 == 0) {
|
|
return 0;
|
|
}
|
|
int i3 = this.bytesRemaining;
|
|
if (i3 == 0) {
|
|
return -1;
|
|
}
|
|
int min = Math.min(i2, i3);
|
|
System.arraycopy(Util.castNonNull(this.data), this.readPosition, bArr, i, min);
|
|
this.readPosition += min;
|
|
this.bytesRemaining -= min;
|
|
bytesTransferred(min);
|
|
return min;
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public Uri getUri() {
|
|
DataSpec dataSpec = this.dataSpec;
|
|
if (dataSpec != null) {
|
|
return dataSpec.uri;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public void close() {
|
|
if (this.data != null) {
|
|
this.data = null;
|
|
transferEnded();
|
|
}
|
|
this.dataSpec = null;
|
|
}
|
|
}
|