CosParseBuf.java 3.64 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.io.stream.InputByteStream
 */
package com.adobe.internal.pdftoolkit.core.cos;

import com.adobe.internal.io.stream.InputByteStream;
import java.io.IOException;
import java.io.InputStream;

final class CosParseBuf
implements InputByteStream {
    private InputByteStream mBaseBuf = null;
    private int mBufferSize = 0;
    private long mOrigPos = 0;
    private int mBaseOffset = 0;
    private int mPos = 0;
    private int mEnd = 0;
    private byte[] mBuffer = null;
    private boolean readTillBufferSize = false;

    CosParseBuf(InputByteStream baseBuf, int bufferSize) throws IOException {
        this.mBaseBuf = baseBuf;
        this.mBufferSize = bufferSize;
        this.mBuffer = new byte[this.mBufferSize];
        this.mOrigPos = baseBuf.getPosition();
        this.mEnd = baseBuf.read(this.mBuffer);
    }

    CosParseBuf(InputByteStream baseBuf, int bufferSize, boolean readTillBufferSize) throws IOException {
        this(baseBuf, bufferSize);
        this.readTillBufferSize = readTillBufferSize;
    }

    public int read() throws IOException {
        if (this.readTillBufferSize && this.mPos == this.mBufferSize) {
            return -1;
        }
        if (this.mPos == this.mEnd) {
            this.mBaseOffset += this.mPos;
            this.mEnd = this.mBaseBuf.read(this.mBuffer);
            if (this.mEnd <= 0) {
                return -1;
            }
            this.mPos = 0;
        }
        return 255 & this.mBuffer[this.mPos++];
    }

    public int unget() {
        if (this.mPos > 0) {
            --this.mPos;
        }
        return this.mBuffer[this.mPos];
    }

    public long getPosition() {
        return this.mOrigPos + (long)this.mBaseOffset + (long)this.mPos;
    }

    public void close() throws IOException {
        this.mBaseBuf.seek(this.mOrigPos + (long)this.mBaseOffset + (long)this.mPos);
        this.mBaseBuf = null;
        this.mBuffer = null;
    }

    public boolean eof() throws IOException {
        if (this.mPos < this.mEnd) {
            return false;
        }
        return this.mBaseBuf.eof();
    }

    public long bytesAvailable() throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: bytesAvailable");
    }

    public boolean exists(byte[] key, long extent) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: exists");
    }

    public long indexOf(byte[] key) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: indexOf");
    }

    public long length() throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: length");
    }

    public int read(byte[] bytes) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: read");
    }

    public int read(byte[] bytes, int position, int length) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: read");
    }

    public InputByteStream seek(long position) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: seek");
    }

    public InputByteStream slice() throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: slice");
    }

    public InputByteStream slice(long begin, long length) throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: slice");
    }

    public InputStream toInputStream() throws IOException {
        throw new IOException("Unimplemented method call on CosParseBuf: toInputStream");
    }
}