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

JMXChunkedOutputStream

public class JMXChunkedOutputStream extends OutputStream

Fields Summary
private OutputStream
out
private byte[]
buffer
private int
bufCount
Constructors Summary
public JMXChunkedOutputStream(OutputStream out)


       
        this.out = out;
        buffer = new byte[8192];
    
Methods Summary
public voidclose()

        if (bufCount > 0)
            flush();
        out.close();
    
public voidflush()

        if (bufCount > 0)
            flushBuffer();
        else
            out.flush();
    
private voidflushBuffer()

        writeObject(buffer, 0, bufCount);
        bufCount = 0;
    
public voidwrite(byte[] b)

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

        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;
        if (bufCount > 0 && (bufCount+len) >= 8192) {
            flushBuffer();
        }
        if (len >= 8192) {
            writeObject(b, off, len);
            return;
        }
        writeBuffer(b, off, len);
    
public voidwrite(int by)

        byte b = (byte) by;
        if (bufCount > 0 && (bufCount+1) >= 8192) {
            flushBuffer();
        }
        buffer[bufCount] = b;
        bufCount++;
    
private voidwriteBuffer(byte[] b, int off, int len)

        System.arraycopy(b, off, buffer, bufCount, len);
        bufCount += len;
    
public voidwriteEOF(int padLen)

        DataOutputStream dO = new DataOutputStream(out);
        dO.writeInt(0);
        // Kludge:: For some wierd reason, the StreamingOutputStream of
        //          HttpURLConnection is not counting the requestmessage object's
        //          length as the number of bytes written.
        //          Hence, we will send some padding bytes at the end to fool
        //          StreamingOutputStream.
        dO.write(new byte[padLen],0,padLen);
        dO.flush();
    
private voidwriteObject(byte[] b, int off, int len)

        DataOutputStream dO = new DataOutputStream(out);
        dO.writeInt(len);
        dO.write(b, off, len);
        dO.flush();