package V1;

import Z0.o;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteOrder;

/* JADX INFO: loaded from: classes.dex */
public class b extends InputStream implements DataInput {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final DataInputStream f7192a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f7193b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public ByteOrder f7194c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public byte[] f7195d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f7196e;

    public b(byte[] bArr) {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
        this(byteArrayInputStream, 0);
        this.f7196e = bArr.length;
    }

    public final void a(int i6) throws IOException {
        int i7 = 0;
        while (i7 < i6) {
            DataInputStream dataInputStream = this.f7192a;
            int i8 = i6 - i7;
            int iSkip = (int) dataInputStream.skip(i8);
            if (iSkip <= 0) {
                if (this.f7195d == null) {
                    this.f7195d = new byte[8192];
                }
                iSkip = dataInputStream.read(this.f7195d, 0, Math.min(8192, i8));
                if (iSkip == -1) {
                    throw new EOFException(o.j(i6, "Reached EOF while skipping ", " bytes."));
                }
            }
            i7 += iSkip;
        }
        this.f7193b += i7;
    }

    @Override // java.io.InputStream
    public final int available() {
        return this.f7192a.available();
    }

    @Override // java.io.InputStream
    public final void mark(int i6) {
        throw new UnsupportedOperationException("Mark is currently unsupported");
    }

    @Override // java.io.InputStream
    public final int read() {
        this.f7193b++;
        return this.f7192a.read();
    }

    @Override // java.io.DataInput
    public final boolean readBoolean() {
        this.f7193b++;
        return this.f7192a.readBoolean();
    }

    @Override // java.io.DataInput
    public final byte readByte() throws IOException {
        this.f7193b++;
        int i6 = this.f7192a.read();
        if (i6 >= 0) {
            return (byte) i6;
        }
        throw new EOFException();
    }

    @Override // java.io.DataInput
    public final char readChar() {
        this.f7193b += 2;
        return this.f7192a.readChar();
    }

    @Override // java.io.DataInput
    public final double readDouble() {
        return Double.longBitsToDouble(readLong());
    }

    @Override // java.io.DataInput
    public final float readFloat() {
        return Float.intBitsToFloat(readInt());
    }

    @Override // java.io.DataInput
    public final void readFully(byte[] bArr, int i6, int i7) throws IOException {
        this.f7193b += i7;
        this.f7192a.readFully(bArr, i6, i7);
    }

    @Override // java.io.DataInput
    public final int readInt() throws IOException {
        this.f7193b += 4;
        DataInputStream dataInputStream = this.f7192a;
        int i6 = dataInputStream.read();
        int i7 = dataInputStream.read();
        int i8 = dataInputStream.read();
        int i9 = dataInputStream.read();
        if ((i6 | i7 | i8 | i9) < 0) {
            throw new EOFException();
        }
        ByteOrder byteOrder = this.f7194c;
        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            return (i9 << 24) + (i8 << 16) + (i7 << 8) + i6;
        }
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            return (i6 << 24) + (i7 << 16) + (i8 << 8) + i9;
        }
        throw new IOException("Invalid byte order: " + this.f7194c);
    }

    @Override // java.io.DataInput
    public final String readLine() {
        Log.d("ExifInterface", "Currently unsupported");
        return null;
    }

    @Override // java.io.DataInput
    public final long readLong() throws IOException {
        long j4;
        long j6;
        this.f7193b += 8;
        DataInputStream dataInputStream = this.f7192a;
        int i6 = dataInputStream.read();
        int i7 = dataInputStream.read();
        int i8 = dataInputStream.read();
        int i9 = dataInputStream.read();
        int i10 = dataInputStream.read();
        int i11 = dataInputStream.read();
        int i12 = dataInputStream.read();
        int i13 = dataInputStream.read();
        if ((i6 | i7 | i8 | i9 | i10 | i11 | i12 | i13) < 0) {
            throw new EOFException();
        }
        ByteOrder byteOrder = this.f7194c;
        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            j4 = (((long) i13) << 56) + (((long) i12) << 48) + (((long) i11) << 40) + (((long) i10) << 32) + (((long) i9) << 24) + (((long) i8) << 16) + (((long) i7) << 8);
            j6 = i6;
        } else {
            if (byteOrder != ByteOrder.BIG_ENDIAN) {
                throw new IOException("Invalid byte order: " + this.f7194c);
            }
            j4 = (((long) i6) << 56) + (((long) i7) << 48) + (((long) i8) << 40) + (((long) i9) << 32) + (((long) i10) << 24) + (((long) i11) << 16) + (((long) i12) << 8);
            j6 = i13;
        }
        return j4 + j6;
    }

    @Override // java.io.DataInput
    public final short readShort() throws IOException {
        this.f7193b += 2;
        DataInputStream dataInputStream = this.f7192a;
        int i6 = dataInputStream.read();
        int i7 = dataInputStream.read();
        if ((i6 | i7) < 0) {
            throw new EOFException();
        }
        ByteOrder byteOrder = this.f7194c;
        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            return (short) ((i7 << 8) + i6);
        }
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            return (short) ((i6 << 8) + i7);
        }
        throw new IOException("Invalid byte order: " + this.f7194c);
    }

    @Override // java.io.DataInput
    public final String readUTF() {
        this.f7193b += 2;
        return this.f7192a.readUTF();
    }

    @Override // java.io.DataInput
    public final int readUnsignedByte() {
        this.f7193b++;
        return this.f7192a.readUnsignedByte();
    }

    @Override // java.io.DataInput
    public final int readUnsignedShort() throws IOException {
        this.f7193b += 2;
        DataInputStream dataInputStream = this.f7192a;
        int i6 = dataInputStream.read();
        int i7 = dataInputStream.read();
        if ((i6 | i7) < 0) {
            throw new EOFException();
        }
        ByteOrder byteOrder = this.f7194c;
        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            return (i7 << 8) + i6;
        }
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            return (i6 << 8) + i7;
        }
        throw new IOException("Invalid byte order: " + this.f7194c);
    }

    @Override // java.io.InputStream
    public final void reset() {
        throw new UnsupportedOperationException("Reset is currently unsupported");
    }

    @Override // java.io.DataInput
    public final int skipBytes(int i6) {
        throw new UnsupportedOperationException("skipBytes is currently unsupported");
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public b(InputStream inputStream) {
        this(inputStream, 0);
        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i6, int i7) throws IOException {
        int i8 = this.f7192a.read(bArr, i6, i7);
        this.f7193b += i8;
        return i8;
    }

    @Override // java.io.DataInput
    public final void readFully(byte[] bArr) throws IOException {
        this.f7193b += bArr.length;
        this.f7192a.readFully(bArr);
    }

    public b(InputStream inputStream, int i6) {
        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        this.f7192a = dataInputStream;
        dataInputStream.mark(0);
        this.f7193b = 0;
        this.f7194c = byteOrder;
        this.f7196e = inputStream instanceof b ? ((b) inputStream).f7196e : -1;
    }
}
