/** * @see java.io.OutputStream#write(int) */ public void write(int c) throws IOException { lastBuffer = lastBuffer.append((byte) c); length++; }
public void handle(byte[] bytes, int length) throws IOException { buffer.append(bytes, 0, length); }
public void handle(byte[] bytes, int length) throws IOException { buffer.append(bytes, 0, length); }
public void handle(byte[] bytes, int length) throws IOException { buffer.append(bytes, 0, length); }
public void handle(byte[] bytes, int length) throws IOException { buffer.append(bytes, 0, length); }
/** * @see java.io.OutputStream#write(byte []) */ public void write(byte[] b) throws IOException { if (b == null) { throw new NullPointerException(); } int limit = b.length; length += limit; lastBuffer = lastBuffer.append(b, 0, limit); }
/** * @see java.io.OutputStream#write(byte[], int, int) */ public void write(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return; } lastBuffer = lastBuffer.append(b, off, len); length += len; }
/** * Appends byte to array if there are unfilled positions in it. Otherwize creates next link in the chain, and appends the * byte to it. * * @param c * @return instance of ByteBuffer to which byte was appended. */ public ByteBuffer append(byte c) { if (next != null) { return next.append(c); } if (usedSize < cacheSize) { bytes[usedSize] = c; usedSize++; return this; } else { next = new ByteBuffer(cacheSize * 2); next.prev = this; return next.append(c); } }
/** * Appends segment of a byte array to array if there are unfilled positions in it. Otherwize creates next link in the chain, * and appends data to it. * * @param bs * @param off * @param len * @return instance of ByteBuffer to which byte array was appended. */ public ByteBuffer append(byte[] bs, int off, int len) { if (next != null) { return next.append(bs, off, len); } if (len + usedSize <= cacheSize) { System.arraycopy(bs, off, bytes, usedSize, len); usedSize += len; return this; } int av = cacheSize - usedSize; if (av > 0) { System.arraycopy(bs, off, bytes, usedSize, av); usedSize += av; off += av; len -= av; } next = new ByteBuffer(cacheSize * 2); next.prev = this; return next.append(bs, off, len); }