/** * Finish writing to a stream. The stream is released. * No further writing may be done until the {@link #start(ByteOutput)} method is again invoked. * * @throws IOException if an error occurs */ protected void finish() throws IOException { try { flush(); } finally { buffer = null; byteOutput = null; } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
/** {@inheritDoc} */ public void writeByte(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining == 0) { flush(); buffer[0] = (byte) v; position = 1; } else { buffer[position++] = (byte) v; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeBoolean(final boolean v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining == 0) { flush(); buffer[0] = (byte) (v ? 1 : 0); position = 1; } else { buffer[position++] = (byte) (v ? 1 : 0); } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void write(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int position = this.position; if (position == buffer.length) { flush(); buffer[0] = (byte) v; this.position = 1; } else { buffer[position] = (byte) v; this.position = position + 1; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeChar(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining < 2) { flush(); buffer[0] = (byte) (v >> 8); buffer[1] = (byte) v; position = 2; } else { final int s = position; position = s + 2; buffer[s] = (byte) (v >> 8); buffer[s+1] = (byte) v; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeShort(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining < 2) { flush(); buffer[0] = (byte) (v >> 8); buffer[1] = (byte) v; position = 2; } else { final int s = position; position = s + 2; buffer[s] = (byte) (v >> 8); buffer[s+1] = (byte) v; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeInt(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining < 4) { flush(); buffer[0] = (byte) (v >> 24); buffer[1] = (byte) (v >> 16); buffer[2] = (byte) (v >> 8); buffer[3] = (byte) v; position = 4; } else { final int s = position; position = s + 4; buffer[s] = (byte) (v >> 24); buffer[s+1] = (byte) (v >> 16); buffer[s+2] = (byte) (v >> 8); buffer[s+3] = (byte) v; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeFloat(final float v) throws IOException { final int bits = Float.floatToIntBits(v); try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining < 4) { flush(); buffer[0] = (byte) (bits >> 24); buffer[1] = (byte) (bits >> 16); buffer[2] = (byte) (bits >> 8); buffer[3] = (byte) bits; position = 4; } else { final int s = position; position = s + 4; buffer[s] = (byte) (bits >> 24); buffer[s+1] = (byte) (bits >> 16); buffer[s+2] = (byte) (bits >> 8); buffer[s+3] = (byte) bits; } } catch (NullPointerException e) { throw notActiveException(); } }
final int remaining = buffer.length - position; if (remaining < 8) { flush(); buffer[0] = (byte) (bits >> 56L); buffer[1] = (byte) (bits >> 48L);
final int remaining = buffer.length - position; if (remaining < 8) { flush(); buffer[0] = (byte) (v >> 56L); buffer[1] = (byte) (v >> 48L);
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }