package p138.p145.p146.p147;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/* JADX INFO: renamed from: ދ.ؠ.֏.މ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C2827 implements Closeable {

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

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Charset f8733;

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

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

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

    /* JADX INFO: renamed from: ދ.ؠ.֏.މ.ؠ$֏, reason: contains not printable characters */
    public class C2828 extends ByteArrayOutputStream {
        public C2828(int i) {
            super(i);
        }

        @Override // java.io.ByteArrayOutputStream
        public String toString() {
            int i = ((ByteArrayOutputStream) this).count;
            try {
                return new String(((ByteArrayOutputStream) this).buf, 0, (i <= 0 || ((ByteArrayOutputStream) this).buf[i + (-1)] != 13) ? ((ByteArrayOutputStream) this).count : i - 1, C2827.this.f8733.name());
            } catch (UnsupportedEncodingException e) {
                throw new AssertionError(e);
            }
        }
    }

    public C2827(InputStream inputStream, Charset charset) {
        if (inputStream == null || charset == null) {
            throw null;
        }
        if (!charset.equals(C2829.f8738)) {
            throw new IllegalArgumentException("Unsupported encoding");
        }
        this.f8732 = inputStream;
        this.f8733 = charset;
        this.f8734 = new byte[8192];
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        synchronized (this.f8732) {
            if (this.f8734 != null) {
                this.f8734 = null;
                this.f8732.close();
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m4947() throws IOException {
        InputStream inputStream = this.f8732;
        byte[] bArr = this.f8734;
        int i = inputStream.read(bArr, 0, bArr.length);
        if (i == -1) {
            throw new EOFException();
        }
        this.f8735 = 0;
        this.f8736 = i;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x002d  */
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public String m4948() {
        int i;
        int i2;
        synchronized (this.f8732) {
            if (this.f8734 == null) {
                throw new IOException("LineReader is closed");
            }
            if (this.f8735 >= this.f8736) {
                m4947();
            }
            for (int i3 = this.f8735; i3 != this.f8736; i3++) {
                if (this.f8734[i3] == 10) {
                    if (i3 != this.f8735) {
                        i2 = i3 - 1;
                        if (this.f8734[i2] != 13) {
                            i2 = i3;
                        }
                    }
                    String str = new String(this.f8734, this.f8735, i2 - this.f8735, this.f8733.name());
                    this.f8735 = i3 + 1;
                    return str;
                }
            }
            C2828 c2828 = new C2828((this.f8736 - this.f8735) + 80);
            loop1: while (true) {
                c2828.write(this.f8734, this.f8735, this.f8736 - this.f8735);
                this.f8736 = -1;
                m4947();
                i = this.f8735;
                while (i != this.f8736) {
                    if (this.f8734[i] == 10) {
                        break loop1;
                    }
                    i++;
                }
            }
            if (i != this.f8735) {
                c2828.write(this.f8734, this.f8735, i - this.f8735);
            }
            this.f8735 = i + 1;
            return c2828.toString();
        }
    }
}
