@Override public void write(final int b) throws IOException { this.lock.lock(); try { Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing"); setInputMode(); if (!this.buffer.hasRemaining()) { flushContent(); setInputMode(); } this.buffer.put((byte)b); } finally { this.lock.unlock(); } }
@Override public void write(final int b) throws IOException { this.lock.lock(); try { Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing"); setInputMode(); if (!this.buffer.hasRemaining()) { flushContent(); setInputMode(); } this.buffer.put((byte)b); } finally { this.lock.unlock(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { if (b == null) { return; } int pos = off; this.lock.lock(); try { Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing"); setInputMode(); int remaining = len; while (remaining > 0) { if (!this.buffer.hasRemaining()) { flushContent(); setInputMode(); } final int chunk = Math.min(remaining, this.buffer.remaining()); this.buffer.put(b, pos, chunk); remaining -= chunk; pos += chunk; } } finally { this.lock.unlock(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { if (b == null) { return; } int pos = off; this.lock.lock(); try { Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing"); setInputMode(); int remaining = len; while (remaining > 0) { if (!this.buffer.hasRemaining()) { flushContent(); setInputMode(); } final int chunk = Math.min(remaining, this.buffer.remaining()); this.buffer.put(b, pos, chunk); remaining -= chunk; pos += chunk; } } finally { this.lock.unlock(); } }