@Override public void write(final int b) throws IOException { buffer[bufferIndex++] = (byte) (b & 0xFF); if (bufferFull()) { compressAndWrite(); } }
@Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Compresses the currently buffered chunk of data and sends it to the output stream * * @throws IOException if issues occur writing to stream */ protected void compressAndWrite() throws IOException { if (bufferIndex <= 0) { return; } deflater.setInput(buffer, 0, bufferIndex); deflater.finish(); final int compressedBytes = deflater.deflate(compressed); writeChunkHeader(compressedBytes); out.write(compressed, 0, compressedBytes); bufferIndex = 0; deflater.reset(); }
final OutputStream dataOut = compress ? new CompressionOutputStream(os) : os; final OutputStream out = new CheckedOutputStream(dataOut, crc);
@Override public void flush() throws IOException { compressAndWrite(); super.flush(); }
private void writeChunkHeader(final int compressedBytes) throws IOException { // If we have already written data, write out a '1' to indicate that we have more data; when we close // the stream, we instead write a '0' to indicate that we are finished sending data. if (dataWritten) { out.write(1); } out.write(SYNC_BYTES); dataWritten = true; writeInt(out, bufferIndex); writeInt(out, compressedBytes); }
while (continueTransaction) { final boolean useGzip = handshakeProperties.isUseGzip(); final OutputStream flowFileOutputStream = useGzip ? new CompressionOutputStream(os) : os; logger.debug("{} Sending {} to {}", new Object[]{this, flowFile, peer});
/** * 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(); } }
private void writeChunkHeader(final int compressedBytes) throws IOException { // If we have already written data, write out a '1' to indicate that we have more data; when we close // the stream, we instead write a '0' to indicate that we are finished sending data. if (dataWritten) { out.write(1); } out.write(SYNC_BYTES); dataWritten = true; writeInt(out, bufferIndex); writeInt(out, compressedBytes); }
@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(); } } }
while (continueTransaction) { final boolean useGzip = handshakeProperties.isUseGzip(); final OutputStream flowFileOutputStream = useGzip ? new CompressionOutputStream(os) : os; logger.debug("{} Sending {} to {}", new Object[]{this, flowFile, peer});
@Override public void flush() throws IOException { compressAndWrite(); super.flush(); }
@Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Compresses the currently buffered chunk of data and sends it to the output stream * * @throws IOException if issues occur writing to stream */ protected void compressAndWrite() throws IOException { if (bufferIndex <= 0) { return; } deflater.setInput(buffer, 0, bufferIndex); deflater.finish(); final int compressedBytes = deflater.deflate(compressed); writeChunkHeader(compressedBytes); out.write(compressed, 0, compressedBytes); bufferIndex = 0; deflater.reset(); }
@Override public void write(final int b) throws IOException { buffer[bufferIndex++] = (byte) (b & 0xFF); if (bufferFull()) { compressAndWrite(); } }
/** * 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 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(); } } }