package com.mbridge.msdk.playercommon.exoplayer2.util; import java.nio.ByteBuffer; import java.nio.charset.Charset; /* loaded from: classes4.dex */ public final class ParsableByteArray { public byte[] data; private int limit; private int position; public ParsableByteArray() { } public final int bytesLeft() { return this.limit - this.position; } public final int getPosition() { return this.position; } public final int limit() { return this.limit; } public final void reset() { this.position = 0; this.limit = 0; } public final void reset(byte[] bArr, int i) { this.data = bArr; this.limit = i; this.position = 0; } public ParsableByteArray(int i) { this.data = new byte[i]; this.limit = i; } public ParsableByteArray(byte[] bArr) { this.data = bArr; this.limit = bArr.length; } public ParsableByteArray(byte[] bArr, int i) { this.data = bArr; this.limit = i; } public final void reset(int i) { reset(capacity() < i ? new byte[i] : this.data, i); } public final void setLimit(int i) { Assertions.checkArgument(i >= 0 && i <= this.data.length); this.limit = i; } public final int capacity() { byte[] bArr = this.data; if (bArr == null) { return 0; } return bArr.length; } public final void setPosition(int i) { Assertions.checkArgument(i >= 0 && i <= this.limit); this.position = i; } public final void skipBytes(int i) { setPosition(this.position + i); } public final void readBytes(ParsableBitArray parsableBitArray, int i) { readBytes(parsableBitArray.data, 0, i); parsableBitArray.setPosition(0); } public final void readBytes(byte[] bArr, int i, int i2) { System.arraycopy(this.data, this.position, bArr, i, i2); this.position += i2; } public final void readBytes(ByteBuffer byteBuffer, int i) { byteBuffer.put(this.data, this.position, i); this.position += i; } public final int peekUnsignedByte() { return this.data[this.position] & 255; } public final char peekChar() { byte[] bArr = this.data; int i = this.position; return (char) ((bArr[i + 1] & 255) | ((bArr[i] & 255) << 8)); } public final int readUnsignedByte() { byte[] bArr = this.data; int i = this.position; this.position = i + 1; return bArr[i] & 255; } public final int readUnsignedShort() { byte[] bArr = this.data; int i = this.position; int i2 = i + 1; int i3 = (bArr[i] & 255) << 8; this.position = i + 2; return (bArr[i2] & 255) | i3; } public final int readLittleEndianUnsignedShort() { byte[] bArr = this.data; int i = this.position; int i2 = i + 1; int i3 = bArr[i] & 255; this.position = i + 2; return ((bArr[i2] & 255) << 8) | i3; } public final short readShort() { byte[] bArr = this.data; int i = this.position; int i2 = i + 1; int i3 = (bArr[i] & 255) << 8; this.position = i + 2; return (short) ((bArr[i2] & 255) | i3); } public final short readLittleEndianShort() { byte[] bArr = this.data; int i = this.position; int i2 = i + 1; int i3 = bArr[i] & 255; this.position = i + 2; return (short) (((bArr[i2] & 255) << 8) | i3); } public final int readUnsignedInt24() { byte[] bArr = this.data; int i = this.position; int i2 = i + 2; int i3 = ((bArr[i + 1] & 255) << 8) | ((bArr[i] & 255) << 16); this.position = i + 3; return (bArr[i2] & 255) | i3; } public final int readInt24() { byte[] bArr = this.data; int i = this.position; int i2 = i + 2; int i3 = ((bArr[i + 1] & 255) << 8) | (((bArr[i] & 255) << 24) >> 8); this.position = i + 3; return (bArr[i2] & 255) | i3; } public final int readLittleEndianInt24() { byte[] bArr = this.data; int i = this.position; int i2 = i + 2; int i3 = ((bArr[i + 1] & 255) << 8) | (bArr[i] & 255); this.position = i + 3; return ((bArr[i2] & 255) << 16) | i3; } public final int readLittleEndianUnsignedInt24() { byte[] bArr = this.data; int i = this.position; int i2 = i + 2; int i3 = ((bArr[i + 1] & 255) << 8) | (bArr[i] & 255); this.position = i + 3; return ((bArr[i2] & 255) << 16) | i3; } public final long readUnsignedInt() { byte[] bArr = this.data; int i = this.position; int i2 = i + 3; long j = ((bArr[i] & 255) << 24) | ((bArr[i + 1] & 255) << 16) | ((bArr[i + 2] & 255) << 8); this.position = i + 4; return (bArr[i2] & 255) | j; } public final long readLittleEndianUnsignedInt() { byte[] bArr = this.data; int i = this.position; int i2 = i + 3; long j = (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16); this.position = i + 4; return ((bArr[i2] & 255) << 24) | j; } public final int readInt() { byte[] bArr = this.data; int i = this.position; int i2 = ((bArr[i + 1] & 255) << 16) | ((bArr[i] & 255) << 24); int i3 = i + 3; int i4 = i2 | ((bArr[i + 2] & 255) << 8); this.position = i + 4; return (bArr[i3] & 255) | i4; } public final int readLittleEndianInt() { byte[] bArr = this.data; int i = this.position; int i2 = ((bArr[i + 1] & 255) << 8) | (bArr[i] & 255); int i3 = i + 3; int i4 = i2 | ((bArr[i + 2] & 255) << 16); this.position = i + 4; return ((bArr[i3] & 255) << 24) | i4; } public final long readLong() { byte[] bArr = this.data; int i = this.position; int i2 = i + 7; long j = ((bArr[i] & 255) << 56) | ((bArr[i + 1] & 255) << 48) | ((bArr[i + 2] & 255) << 40) | ((bArr[i + 3] & 255) << 32) | ((bArr[i + 4] & 255) << 24) | ((bArr[i + 5] & 255) << 16) | ((bArr[i + 6] & 255) << 8); this.position = i + 8; return (bArr[i2] & 255) | j; } public final long readLittleEndianLong() { byte[] bArr = this.data; int i = this.position; int i2 = i + 7; long j = (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 3] & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48); this.position = i + 8; return ((bArr[i2] & 255) << 56) | j; } public final int readUnsignedFixedPoint1616() { byte[] bArr = this.data; int i = this.position; int i2 = (bArr[i + 1] & 255) | ((bArr[i] & 255) << 8); this.position = i + 4; return i2; } public final int readSynchSafeInt() { return (readUnsignedByte() << 21) | (readUnsignedByte() << 14) | (readUnsignedByte() << 7) | readUnsignedByte(); } public final int readUnsignedIntToInt() { int readInt = readInt(); if (readInt >= 0) { return readInt; } throw new IllegalStateException("Top bit not zero: " + readInt); } public final int readLittleEndianUnsignedIntToInt() { int readLittleEndianInt = readLittleEndianInt(); if (readLittleEndianInt >= 0) { return readLittleEndianInt; } throw new IllegalStateException("Top bit not zero: " + readLittleEndianInt); } public final long readUnsignedLongToLong() { long readLong = readLong(); if (readLong >= 0) { return readLong; } throw new IllegalStateException("Top bit not zero: " + readLong); } public final float readFloat() { return Float.intBitsToFloat(readInt()); } public final double readDouble() { return Double.longBitsToDouble(readLong()); } public final String readString(int i) { return readString(i, Charset.forName("UTF-8")); } public final String readString(int i, Charset charset) { String str = new String(this.data, this.position, i, charset); this.position += i; return str; } public final String readNullTerminatedString(int i) { if (i == 0) { return ""; } int i2 = this.position; int i3 = (i2 + i) - 1; String fromUtf8Bytes = Util.fromUtf8Bytes(this.data, i2, (i3 >= this.limit || this.data[i3] != 0) ? i : i - 1); this.position += i; return fromUtf8Bytes; } public final String readNullTerminatedString() { if (bytesLeft() == 0) { return null; } int i = this.position; while (i < this.limit && this.data[i] != 0) { i++; } byte[] bArr = this.data; int i2 = this.position; String fromUtf8Bytes = Util.fromUtf8Bytes(bArr, i2, i - i2); this.position = i; if (i < this.limit) { this.position = i + 1; } return fromUtf8Bytes; } public final String readLine() { if (bytesLeft() == 0) { return null; } int i = this.position; while (i < this.limit && !Util.isLinebreak(this.data[i])) { i++; } int i2 = this.position; if (i - i2 >= 3) { byte[] bArr = this.data; if (bArr[i2] == -17 && bArr[i2 + 1] == -69 && bArr[i2 + 2] == -65) { this.position = i2 + 3; } } byte[] bArr2 = this.data; int i3 = this.position; String fromUtf8Bytes = Util.fromUtf8Bytes(bArr2, i3, i - i3); this.position = i; int i4 = this.limit; if (i == i4) { return fromUtf8Bytes; } byte[] bArr3 = this.data; if (bArr3[i] == 13) { int i5 = i + 1; this.position = i5; if (i5 == i4) { return fromUtf8Bytes; } } int i6 = this.position; if (bArr3[i6] == 10) { this.position = i6 + 1; } return fromUtf8Bytes; } public final long readUtf8EncodedLong() { int i; int i2; long j = this.data[this.position]; int i3 = 7; while (true) { if (i3 < 0) { break; } if (((1 << i3) & j) != 0) { i3--; } else if (i3 < 6) { j &= r6 - 1; i2 = 7 - i3; } else if (i3 == 7) { i2 = 1; } } i2 = 0; if (i2 == 0) { throw new NumberFormatException("Invalid UTF-8 sequence first byte: " + j); } for (i = 1; i < i2; i++) { if ((this.data[this.position + i] & 192) != 128) { throw new NumberFormatException("Invalid UTF-8 sequence continuation byte: " + j); } j = (j << 6) | (r3 & 63); } this.position += i2; return j; } }