@Override public void flush() throws IOException { compressAndWrite(); super.flush(); }
/** * Flushes remaining buffer and calls {@link Deflater#end()} to free acquired memory to prevent OutOfMemory error. * @throws IOException for any issues closing underlying stream */ @Override public void close() throws IOException { compressAndWrite(); out.write(0); // indicate that the stream is finished. out.flush(); deflater.end(); } }
@Override public void write(final int b) throws IOException { buffer[bufferIndex++] = (byte) (b & 0xFF); if (bufferFull()) { compressAndWrite(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { int bytesLeft = len; while (bytesLeft > 0) { final int free = buffer.length - bufferIndex; final int bytesThisIteration = Math.min(bytesLeft, free); System.arraycopy(b, off + len - bytesLeft, buffer, bufferIndex, bytesThisIteration); bufferIndex += bytesThisIteration; bytesLeft -= bytesThisIteration; if (bufferFull()) { compressAndWrite(); } } }
@Override public void flush() throws IOException { compressAndWrite(); super.flush(); }
/** * Flushes remaining buffer and calls {@link Deflater#end()} to free acquired memory to prevent OutOfMemory error. * @throws IOException for any issues closing underlying stream */ @Override public void close() throws IOException { compressAndWrite(); out.write(0); // indicate that the stream is finished. out.flush(); deflater.end(); } }
@Override public void write(final int b) throws IOException { buffer[bufferIndex++] = (byte) (b & 0xFF); if (bufferFull()) { compressAndWrite(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { int bytesLeft = len; while (bytesLeft > 0) { final int free = buffer.length - bufferIndex; final int bytesThisIteration = Math.min(bytesLeft, free); System.arraycopy(b, off + len - bytesLeft, buffer, bufferIndex, bytesThisIteration); bufferIndex += bytesThisIteration; bytesLeft -= bytesThisIteration; if (bufferFull()) { compressAndWrite(); } } }