package p138.p329.p362.p370;

import com.hierynomus.mssmb2.SMBApiException;
import com.hierynomus.protocol.transport.TransportException;
import java.io.InputStream;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p329.p341.EnumC6158;
import p138.p329.p346.C6231;
import p138.p329.p346.p347.C6261;
import p138.p329.p346.p347.C6262;
import p138.p329.p362.InterfaceC6338;
import p463.p481.C7162;
import p463.p481.InterfaceC7161;

/* JADX INFO: renamed from: ދ.ށ.މ.މ.ނ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6398 extends InputStream {

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public static final InterfaceC7161 f17856 = C7162.m10575((Class<?>) C6398.class);

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final long f17857;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public C6396 f17858;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public long f17859 = 0;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f17860 = 0;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public byte[] f17861;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public InterfaceC6338 f17862;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public boolean f17863;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public Future<C6262> f17864;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public int f17865;

    public C6398(C6396 c6396, int i, long j, InterfaceC6338 interfaceC6338) {
        this.f17858 = c6396;
        this.f17865 = i;
        this.f17862 = interfaceC6338;
        this.f17857 = j;
    }

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

    @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f17863 = true;
        this.f17858 = null;
        this.f17861 = null;
    }

    @Override // java.io.InputStream
    public int read() {
        byte[] bArr = this.f17861;
        if (bArr == null || this.f17860 >= bArr.length) {
            m9626();
        }
        if (this.f17863) {
            return -1;
        }
        byte[] bArr2 = this.f17861;
        int i = this.f17860;
        this.f17860 = i + 1;
        return bArr2[i] & 255;
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr) {
        return read(bArr, 0, bArr.length);
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr, int i, int i2) {
        byte[] bArr2 = this.f17861;
        if (bArr2 == null || this.f17860 >= bArr2.length) {
            m9626();
        }
        if (this.f17863) {
            return -1;
        }
        byte[] bArr3 = this.f17861;
        int length = bArr3.length;
        int i3 = this.f17860;
        if (length - i3 <= i2) {
            i2 = bArr3.length - i3;
        }
        System.arraycopy(this.f17861, this.f17860, bArr, i, i2);
        this.f17860 += i2;
        return i2;
    }

    @Override // java.io.InputStream
    public long skip(long j) {
        byte[] bArr = this.f17861;
        if (bArr == null) {
            this.f17859 += j;
        } else {
            int i = this.f17860;
            if (((long) i) + j < bArr.length) {
                this.f17860 = (int) (((long) i) + j);
            } else {
                this.f17859 = ((((long) i) + j) - ((long) bArr.length)) + this.f17859;
                this.f17861 = null;
                this.f17864 = null;
            }
        }
        return j;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9626() {
        if (this.f17863) {
            return;
        }
        if (this.f17864 == null) {
            this.f17864 = m9627();
        }
        C6262 c6262 = (C6262) C4303.m7011(this.f17864, this.f17857, TimeUnit.MILLISECONDS, TransportException.f2172);
        if (((C6231) c6262.f17677).f17394 == EnumC6158.STATUS_SUCCESS.f17193) {
            this.f17861 = c6262.f17511;
            this.f17860 = 0;
            long j = this.f17859;
            long j2 = c6262.f17510;
            long j3 = j + j2;
            this.f17859 = j3;
            InterfaceC6338 interfaceC6338 = this.f17862;
            if (interfaceC6338 != null) {
                interfaceC6338.m9557(j2, j3);
            }
        }
        long j4 = ((C6231) c6262.f17677).f17394;
        if (j4 == EnumC6158.STATUS_END_OF_FILE.f17193 || c6262.f17510 == 0) {
            f17856.mo10573("EOF, {} bytes read", Long.valueOf(this.f17859));
            this.f17863 = true;
        } else {
            if (j4 == EnumC6158.STATUS_SUCCESS.f17193) {
                this.f17864 = m9627();
                return;
            }
            throw new SMBApiException((C6231) c6262.f17677, "Read failed for " + this);
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Future<C6262> m9627() {
        C6396 c6396 = this.f17858;
        long j = this.f17859;
        int i = this.f17865;
        C6391 c6391 = c6396.f17846;
        return c6391.m9633(new C6261(c6391.f17889, c6396.f17847, c6391.f17896, c6391.f17887, j, Math.min(i, c6391.f17890)));
    }
}
