Code example for ByteArrayBuffer

Methods: append, buffer, clear, isFull, length

-1
    public int available() { 
        return capacity() - length(); 
    } 
 
    protected void flushBuffer() throws IOException { 
        int len = this.buffer.length(); 
        if (len > 0) { 
            this.outstream.write(this.buffer.buffer(), 0, len); 
            this.buffer.clear(); 
            this.metrics.incrementBytesTransferred(len); 
        } 
    } 
 
    public void flush() throws IOException { 
        flushBuffer(); 
        this.outstream.flush(); 
    } 
 
    public void write(final byte[] b, int off, int len) throws IOException { 
        if (b == null) { 
            return; 
        } 
        // Do not want to buffer large-ish chunks 
        // if the byte array is larger then MIN_CHUNK_LIMIT 
        // write it directly to the output stream 
        if (len > this.minChunkLimit || len > this.buffer.capacity()) { 
            // flush the buffer 
            flushBuffer(); 
            // write directly to the out stream 
            this.outstream.write(b, off, len); 
            this.metrics.incrementBytesTransferred(len); 
        } else { 
            // Do not let the buffer grow unnecessarily 
            int freecapacity = this.buffer.capacity() - this.buffer.length(); 
            if (len > freecapacity) { 
                // flush the buffer 
                flushBuffer(); 
            } 
            // buffer 
            this.buffer.append(b, off, len); 
        } 
    } 
 
    public void write(final byte[] b) throws IOException { 
        if (b == null) { 
            return; 
        } 
        write(b, 0, b.length); 
    } 
 
    public void write(int b) throws IOException { 
        if (this.buffer.isFull()) { 
            flushBuffer(); 
        } 
        this.buffer.append(b); 
    } 
 
    /** 
     * Writes characters from the specified string followed by a line delimiter 
     * to this session buffer.