Rabbit-R1/android (non root)/java/sources/com/google/android/exoplayer2/upstream/ByteArrayDataSink.java
2024-05-21 17:08:36 -04:00

39 lines
1.3 KiB
Java

package com.google.android.exoplayer2.upstream;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/* loaded from: classes2.dex */
public final class ByteArrayDataSink implements DataSink {
private ByteArrayOutputStream stream;
@Override // com.google.android.exoplayer2.upstream.DataSink
public void open(DataSpec dataSpec) {
if (dataSpec.length == -1) {
this.stream = new ByteArrayOutputStream();
} else {
Assertions.checkArgument(dataSpec.length <= 2147483647L);
this.stream = new ByteArrayOutputStream((int) dataSpec.length);
}
}
@Override // com.google.android.exoplayer2.upstream.DataSink
public void close() throws IOException {
((ByteArrayOutputStream) Util.castNonNull(this.stream)).close();
}
@Override // com.google.android.exoplayer2.upstream.DataSink
public void write(byte[] bArr, int i, int i2) {
((ByteArrayOutputStream) Util.castNonNull(this.stream)).write(bArr, i, i2);
}
public byte[] getData() {
ByteArrayOutputStream byteArrayOutputStream = this.stream;
if (byteArrayOutputStream == null) {
return null;
}
return byteArrayOutputStream.toByteArray();
}
}