mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 01:22:33 -06:00
82 lines
2.6 KiB
Java
82 lines
2.6 KiB
Java
package com.google.android.exoplayer2.upstream;
|
|
|
|
import android.net.Uri;
|
|
import com.google.android.exoplayer2.util.Assertions;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class TeeDataSource implements DataSource {
|
|
private long bytesRemaining;
|
|
private final DataSink dataSink;
|
|
private boolean dataSinkNeedsClosing;
|
|
private final DataSource upstream;
|
|
|
|
public TeeDataSource(DataSource dataSource, DataSink dataSink) {
|
|
this.upstream = (DataSource) Assertions.checkNotNull(dataSource);
|
|
this.dataSink = (DataSink) Assertions.checkNotNull(dataSink);
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public void addTransferListener(TransferListener transferListener) {
|
|
Assertions.checkNotNull(transferListener);
|
|
this.upstream.addTransferListener(transferListener);
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public long open(DataSpec dataSpec) throws IOException {
|
|
long open = this.upstream.open(dataSpec);
|
|
this.bytesRemaining = open;
|
|
if (open == 0) {
|
|
return 0L;
|
|
}
|
|
if (dataSpec.length == -1) {
|
|
long j = this.bytesRemaining;
|
|
if (j != -1) {
|
|
dataSpec = dataSpec.subrange(0L, j);
|
|
}
|
|
}
|
|
this.dataSinkNeedsClosing = true;
|
|
this.dataSink.open(dataSpec);
|
|
return this.bytesRemaining;
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataReader
|
|
public int read(byte[] bArr, int i, int i2) throws IOException {
|
|
if (this.bytesRemaining == 0) {
|
|
return -1;
|
|
}
|
|
int read = this.upstream.read(bArr, i, i2);
|
|
if (read > 0) {
|
|
this.dataSink.write(bArr, i, read);
|
|
long j = this.bytesRemaining;
|
|
if (j != -1) {
|
|
this.bytesRemaining = j - read;
|
|
}
|
|
}
|
|
return read;
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public Uri getUri() {
|
|
return this.upstream.getUri();
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public Map<String, List<String>> getResponseHeaders() {
|
|
return this.upstream.getResponseHeaders();
|
|
}
|
|
|
|
@Override // com.google.android.exoplayer2.upstream.DataSource
|
|
public void close() throws IOException {
|
|
try {
|
|
this.upstream.close();
|
|
} finally {
|
|
if (this.dataSinkNeedsClosing) {
|
|
this.dataSinkNeedsClosing = false;
|
|
this.dataSink.close();
|
|
}
|
|
}
|
|
}
|
|
}
|