/** * Writes len bytes from the specified byte array starting at offset off to this output stream. The general * contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; * element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation. * * @param bytes the data * @param startIndex the start offset in the data * @param numBytes the number of bytes to write */ @Override public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException { assert(numUncompressedBytes < uncompressedBuffer.length); while (numBytes > 0) { final int bytesToWrite = Math.min(uncompressedBuffer.length - numUncompressedBytes, numBytes); System.arraycopy(bytes, startIndex, uncompressedBuffer, numUncompressedBytes, bytesToWrite); numUncompressedBytes += bytesToWrite; startIndex += bytesToWrite; numBytes -= bytesToWrite; assert(numBytes >= 0); if (numUncompressedBytes == uncompressedBuffer.length) { deflateBlock(); } } }
/** * WARNING: flush() affects the output format, because it causes the current contents of uncompressedBuffer * to be compressed and written, even if it isn't full. Unless you know what you're doing, don't call flush(). * Instead, call close(), which will flush any unwritten data before closing the underlying stream. * */ @Override public void flush() throws IOException { while (numUncompressedBytes > 0) { deflateBlock(); } codec.getOutputStream().flush(); }
/** * Writes len bytes from the specified byte array starting at offset off to this output stream. The general * contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; * element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation. * * @param bytes the data * @param startIndex the start offset in the data * @param numBytes the number of bytes to write */ @Override public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException { assert(numUncompressedBytes < uncompressedBuffer.length); while (numBytes > 0) { final int bytesToWrite = Math.min(uncompressedBuffer.length - numUncompressedBytes, numBytes); System.arraycopy(bytes, startIndex, uncompressedBuffer, numUncompressedBytes, bytesToWrite); numUncompressedBytes += bytesToWrite; startIndex += bytesToWrite; numBytes -= bytesToWrite; assert(numBytes >= 0); if (numUncompressedBytes == uncompressedBuffer.length) { deflateBlock(); } } }
/** * Writes len bytes from the specified byte array starting at offset off to this output stream. The general * contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; * element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation. * * @param bytes the data * @param startIndex the start offset in the data * @param numBytes the number of bytes to write */ @Override public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException { assert(numUncompressedBytes < uncompressedBuffer.length); while (numBytes > 0) { final int bytesToWrite = Math.min(uncompressedBuffer.length - numUncompressedBytes, numBytes); System.arraycopy(bytes, startIndex, uncompressedBuffer, numUncompressedBytes, bytesToWrite); numUncompressedBytes += bytesToWrite; startIndex += bytesToWrite; numBytes -= bytesToWrite; assert(numBytes >= 0); if (numUncompressedBytes == uncompressedBuffer.length) { deflateBlock(); } } }
/** * WARNING: flush() affects the output format, because it causes the current contents of uncompressedBuffer * to be compressed and written, even if it isn't full. Unless you know what you're doing, don't call flush(). * Instead, call close(), which will flush any unwritten data before closing the underlying stream. * */ @Override public void flush() throws IOException { while (numUncompressedBytes > 0) { deflateBlock(); } codec.getOutputStream().flush(); }
/** * WARNING: flush() affects the output format, because it causes the current contents of uncompressedBuffer * to be compressed and written, even if it isn't full. Unless you know what you're doing, don't call flush(). * Instead, call close(), which will flush any unwritten data before closing the underlying stream. * */ @Override public void flush() throws IOException { while (numUncompressedBytes > 0) { deflateBlock(); } codec.getOutputStream().flush(); }