package com.ss.android.ugc.effectmanager.disklrucache;

import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.effectmanager.common.utils.FileUtils;
import java.io.Closeable;
import java.io.EOFException;
import java.io.InputStream;
import java.nio.charset.Charset;

public class StrictLineReader implements Closeable {
    public byte[] buf;
    public final Charset charset;
    public int end;
    public final InputStream in;
    public int pos;

    static {
        Covode.recordClassIndex(125342);
    }

    public boolean hasUnterminatedLine() {
        if (this.end == -1) {
            return true;
        }
        return false;
    }

    public void close() {
        MethodCollector.i(11003);
        synchronized (this.in) {
            try {
                if (this.buf != null) {
                    this.buf = null;
                    this.in.close();
                }
            } finally {
                MethodCollector.o(11003);
            }
        }
    }

    private void fillBuf() {
        MethodCollector.i(11468);
        InputStream inputStream = this.in;
        byte[] bArr = this.buf;
        int read = inputStream.read(bArr, 0, bArr.length);
        if (read != -1) {
            this.pos = 0;
            this.end = read;
            MethodCollector.o(11468);
            return;
        }
        EOFException eOFException = new EOFException();
        MethodCollector.o(11468);
        throw eOFException;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:16:0x002d, code lost:
        if (r1[r5] == 13) goto L_0x002f;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public java.lang.String readLine() {
        /*
            r9 = this;
            r8 = 11253(0x2bf5, float:1.5769E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r8)
            java.io.InputStream r4 = r9.in
            monitor-enter(r4)
            byte[] r0 = r9.buf     // Catch:{ all -> 0x009b }
            if (r0 == 0) goto L_0x0090
            int r1 = r9.pos     // Catch:{ all -> 0x009b }
            int r0 = r9.end     // Catch:{ all -> 0x009b }
            if (r1 < r0) goto L_0x0015
            r9.fillBuf()     // Catch:{ all -> 0x009b }
        L_0x0015:
            int r7 = r9.pos     // Catch:{ all -> 0x009b }
        L_0x0017:
            int r0 = r9.end     // Catch:{ all -> 0x009b }
            r6 = 10
            if (r7 == r0) goto L_0x004e
            byte[] r1 = r9.buf     // Catch:{ all -> 0x009b }
            byte r0 = r1[r7]     // Catch:{ all -> 0x009b }
            if (r0 != r6) goto L_0x0047
            int r0 = r9.pos     // Catch:{ all -> 0x009b }
            if (r7 == r0) goto L_0x0045
            int r5 = r7 + -1
            byte r1 = r1[r5]     // Catch:{ all -> 0x009b }
            r0 = 13
            if (r1 != r0) goto L_0x0045
        L_0x002f:
            java.lang.String r3 = new java.lang.String     // Catch:{ all -> 0x009b }
            byte[] r2 = r9.buf     // Catch:{ all -> 0x009b }
            int r1 = r9.pos     // Catch:{ all -> 0x009b }
            int r5 = r5 - r1
            java.nio.charset.Charset r0 = r9.charset     // Catch:{ all -> 0x009b }
            java.lang.String r0 = r0.name()     // Catch:{ all -> 0x009b }
            r3.<init>(r2, r1, r5, r0)     // Catch:{ all -> 0x009b }
            int r0 = r7 + 1
            r9.pos = r0     // Catch:{ all -> 0x009b }
            monitor-exit(r4)     // Catch:{ all -> 0x009b }
            goto L_0x004a
        L_0x0045:
            r5 = r7
            goto L_0x002f
        L_0x0047:
            int r7 = r7 + 1
            goto L_0x0017
        L_0x004a:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r8)
            return r3
        L_0x004e:
            com.ss.android.ugc.effectmanager.disklrucache.StrictLineReader$1 r5 = new com.ss.android.ugc.effectmanager.disklrucache.StrictLineReader$1     // Catch:{ all -> 0x009b }
            int r1 = r9.end     // Catch:{ all -> 0x009b }
            int r0 = r9.pos     // Catch:{ all -> 0x009b }
            int r1 = r1 - r0
            int r0 = r1 + 80
            r5.<init>(r0)     // Catch:{ all -> 0x009b }
        L_0x005a:
            byte[] r2 = r9.buf     // Catch:{ all -> 0x009b }
            int r1 = r9.pos     // Catch:{ all -> 0x009b }
            int r0 = r9.end     // Catch:{ all -> 0x009b }
            int r0 = r0 - r1
            r5.write(r2, r1, r0)     // Catch:{ all -> 0x009b }
            r0 = -1
            r9.end = r0     // Catch:{ all -> 0x009b }
            r9.fillBuf()     // Catch:{ all -> 0x009b }
            int r3 = r9.pos     // Catch:{ all -> 0x009b }
        L_0x006c:
            int r0 = r9.end     // Catch:{ all -> 0x009b }
            if (r3 == r0) goto L_0x005a
            byte[] r2 = r9.buf     // Catch:{ all -> 0x009b }
            byte r0 = r2[r3]     // Catch:{ all -> 0x009b }
            if (r0 != r6) goto L_0x0089
            int r1 = r9.pos     // Catch:{ all -> 0x009b }
            if (r3 == r1) goto L_0x007f
            int r0 = r3 - r1
            r5.write(r2, r1, r0)     // Catch:{ all -> 0x009b }
        L_0x007f:
            int r0 = r3 + 1
            r9.pos = r0     // Catch:{ all -> 0x009b }
            java.lang.String r0 = r5.toString()     // Catch:{ all -> 0x009b }
            monitor-exit(r4)     // Catch:{ all -> 0x009b }
            goto L_0x008c
        L_0x0089:
            int r3 = r3 + 1
            goto L_0x006c
        L_0x008c:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r8)
            return r0
        L_0x0090:
            java.io.IOException r1 = new java.io.IOException     // Catch:{ all -> 0x009b }
            java.lang.String r0 = "LineReader is closed"
            r1.<init>(r0)     // Catch:{ all -> 0x009b }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r8)     // Catch:{ all -> 0x009b }
            throw r1     // Catch:{ all -> 0x009b }
        L_0x009b:
            r0 = move-exception
            monitor-exit(r4)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r8)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.effectmanager.disklrucache.StrictLineReader.readLine():java.lang.String");
    }

    public StrictLineReader(InputStream inputStream, Charset charset2) {
        this(inputStream, FileUtils.BUFFER_SIZE, charset2);
    }

    public StrictLineReader(InputStream inputStream, int i, Charset charset2) {
        if (inputStream == null || charset2 == null) {
            throw null;
        } else if (i < 0) {
            throw new IllegalArgumentException("capacity <= 0");
        } else if (charset2.equals(Util.US_ASCII)) {
            this.in = inputStream;
            this.charset = charset2;
            this.buf = new byte[i];
        } else {
            throw new IllegalArgumentException("Unsupported encoding");
        }
    }
}
