FileDocCategorySizeDatePackage
JMXChunkedInputStream.javaAPI DocGlassfish v2 API5877Fri May 04 22:36:32 BST 2007com.sun.enterprise.admin.jmx.remote.streams

JMXChunkedInputStream

public class JMXChunkedInputStream extends InputStream

Fields Summary
private InputStream
in
private byte[]
buffer
private int
remainderInBuf
private int
remainderInChannel
private int
idx
private boolean
EOF
Constructors Summary
public JMXChunkedInputStream(InputStream in)


       
        this.in = in;
    
Methods Summary
public intavailable()

        return remainderInBuf;
    
public voidclose()

        in.close();
    
public voidmark(int readLimit)

        return;
    
public booleanmarkSupported()

        return false;
    
public intread(byte[] b)

        if (b == null)
            throw (new NullPointerException("byte array is null"));
        return read(b, 0, b.length);
    
public intread(byte[] b, int off, int len)

        if (EOF)
            return -1;
        if (b == null)
            throw (new NullPointerException("byte array is null"));
        if (off < 0 || len < 0 || (off+len) > b.length)
            throw (new IndexOutOfBoundsException(
                                    "offset="+off+
                                    ", len="+len+
                                    ", (off+len)="+(off+len)+
                                    ", b.length="+b.length+
                                    ", (off+len)>b.length="+
                                        ((off+len)>b.length)));
        if (len == 0)
            return 0;

        if (remainderInBuf == 0)
            readObject();
        if (EOF)
            return -1;
        int len1 = (len > remainderInBuf) ? remainderInBuf : len;
        System.arraycopy(buffer, idx, b, off, len1);
        idx += len1;
        remainderInBuf -= len1;
        return len1;
    
public intread()

        if (EOF)
            return -1;
        byte ret = -1;
        if (remainderInBuf == 0)
            readObject();
        if (EOF)
            return -1;
        ret = buffer[idx++];
        remainderInBuf--;
        return ret;
    
private voidreadObject()

        try {
            DataInputStream dI = new DataInputStream(in);
            int len = 0;
            if (remainderInChannel > 0)
                len = remainderInChannel;
            else {
                remainderInChannel = len = dI.readInt();
                if (len <= 0) {
                    setEOF();
                    return;
                }
            }

            buffer = new byte[len];
            remainderInBuf = dI.read(buffer, 0, len);
            if (remainderInBuf == -1) {
                setEOF();
                return;
            }
            remainderInChannel -= remainderInBuf;
            idx = 0;
        } catch (IOException ioe) {
            if (ioe instanceof java.io.EOFException ||
                ioe.getMessage().indexOf("EOF") != -1) {
                setEOF();
                return;
            } else
                throw ioe;
        }
    
public voidreset()

        throw (new IOException("markSupported = false"));
    
private voidsetEOF()

        EOF = true;
        buffer = null;
        remainderInBuf = 0;
        idx = 0;
    
public longskip(int n)

        if (EOF)
            return 0;
        if (n <= 0)
            return 0;
        if (remainderInBuf >= n) {
            idx += n;
            remainderInBuf -= n;
            return n;
        }
        int skipped = remainderInBuf;
        n -= skipped;
        remainderInBuf = 0;
        idx = 0;
        readObject();
        if (EOF)
            return skipped;
        idx += n;
        remainderInBuf -= n;
        skipped += n;
        return skipped;