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