@Override public void flush() throws IOException { flushBuffer(); this.writer.flush(); }
@Override public void write(final String str, int off, int len) throws IOException { if (len >= BUFFER_SIZE) { flushBuffer(); this.writer.write(str, off, len); return; } final int available = BUFFER_SIZE - this.count; if (available < len) { str.getChars(off, off + available, this.buffer, this.count); this.count += available; off += available; len -= available; flushBuffer(); } str.getChars(off, off + len, this.buffer, this.count); this.count += len; }
@Override public void write(final char[] cbuf, int off, int len) throws IOException { if (len >= BUFFER_SIZE) { flushBuffer(); this.writer.write(cbuf, off, len); return; } final int available = BUFFER_SIZE - this.count; if (available < len) { System.arraycopy(cbuf, off, this.buffer, this.count, available); this.count += available; off += available; len -= available; flushBuffer(); } System.arraycopy(cbuf, off, this.buffer, this.count, len); this.count += len; }
@Override public void close() throws IOException { synchronized (this.buffer) { if (this.closed) { return; } this.closed = true; } flushBuffer(); this.writer.close(); // this.count = BUFFER_SIZE; // fail soon in case a new write // request is received }
@Override public void write(final int c) throws IOException { if (this.count >= BUFFER_SIZE) { flushBuffer(); } this.buffer[this.count++] = (char) c; }