package ඓ.ῲ.K.ᨨ;

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;

/* renamed from: ඓ.ῲ.K.ᨨ.ῲ  reason: contains not printable characters */
/* compiled from: StrictLineReader */
public class C1153 implements Closeable {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final Charset f4631;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f4632;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final InputStream f4633;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f4634;

    /* renamed from: 㸾  reason: contains not printable characters */
    public byte[] f4635;

    /* renamed from: ඓ.ῲ.K.ᨨ.ῲ$K  reason: contains not printable characters */
    /* compiled from: StrictLineReader */
    public class C1154 extends ByteArrayOutputStream {
        public C1154(int i) {
            super(i);
        }

        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, C1153.this.f4631.name());
            } catch (UnsupportedEncodingException e) {
                throw new AssertionError(e);
            }
        }
    }

    public C1153(InputStream inputStream, Charset charset) {
        if (inputStream == null || charset == null) {
            throw new NullPointerException();
        } else if (charset.equals(C1152.f4630)) {
            this.f4633 = inputStream;
            this.f4631 = charset;
            this.f4635 = new byte[8192];
        } else {
            throw new IllegalArgumentException("Unsupported encoding");
        }
    }

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

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final void m3080() throws IOException {
        InputStream inputStream = this.f4633;
        byte[] bArr = this.f4635;
        int read = inputStream.read(bArr, 0, bArr.length);
        if (read != -1) {
            this.f4632 = 0;
            this.f4634 = read;
            return;
        }
        throw new EOFException();
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public String m3081() throws IOException {
        int i;
        int i2;
        synchronized (this.f4633) {
            if (this.f4635 != null) {
                if (this.f4632 >= this.f4634) {
                    m3080();
                }
                for (int i3 = this.f4632; i3 != this.f4634; i3++) {
                    if (this.f4635[i3] == 10) {
                        if (i3 != this.f4632) {
                            i2 = i3 - 1;
                            if (this.f4635[i2] == 13) {
                                String str = new String(this.f4635, this.f4632, i2 - this.f4632, this.f4631.name());
                                this.f4632 = i3 + 1;
                                return str;
                            }
                        }
                        i2 = i3;
                        String str2 = new String(this.f4635, this.f4632, i2 - this.f4632, this.f4631.name());
                        this.f4632 = i3 + 1;
                        return str2;
                    }
                }
                C1154 k = new C1154((this.f4634 - this.f4632) + 80);
                loop1:
                while (true) {
                    k.write(this.f4635, this.f4632, this.f4634 - this.f4632);
                    this.f4634 = -1;
                    m3080();
                    i = this.f4632;
                    while (true) {
                        if (i != this.f4634) {
                            if (this.f4635[i] == 10) {
                                break loop1;
                            }
                            i++;
                        }
                    }
                }
                if (i != this.f4632) {
                    k.write(this.f4635, this.f4632, i - this.f4632);
                }
                this.f4632 = i + 1;
                return k.toString();
            }
            throw new IOException("LineReader is closed");
        }
    }
}
