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