// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.mime;

import java.io.IOException;
import org.bouncycastle.util.Strings;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

class LineReader
{
    private final InputStream src;
    private int lastC;
    
    LineReader(final InputStream src) {
        this.lastC = -1;
        this.src = src;
    }
    
    String readLine() throws IOException {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int b;
        if (this.lastC != -1) {
            if (this.lastC == 13) {
                return "";
            }
            b = this.lastC;
            this.lastC = -1;
        }
        else {
            b = this.src.read();
        }
        while (b >= 0 && b != 13 && b != 10) {
            byteArrayOutputStream.write(b);
            b = this.src.read();
        }
        if (b == 13) {
            final int read = this.src.read();
            if (read != 10 && read >= 0) {
                this.lastC = read;
            }
        }
        if (b < 0) {
            return null;
        }
        return Strings.fromUTF8ByteArray(byteArrayOutputStream.toByteArray());
    }
}
