/** * Method for encoding individual chunk, writing it to given output stream. */ public void encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out) throws IOException { if (len >= MIN_BLOCK_TO_COMPRESS) { // If we have non-trivial block, and can compress it by at least // 2 bytes (since header is 2 bytes longer), let's compress: int compEnd = tryCompress(data, offset, offset+len, _encodeBuffer, LZFChunk.HEADER_LEN_COMPRESSED); final int compLen = compEnd - LZFChunk.HEADER_LEN_COMPRESSED; if (compLen < (len-2)) { // yes, compressed block is smaller (consider header is 2 bytes longer) LZFChunk.appendCompressedHeader(len, compLen, _encodeBuffer, 0); out.write(_encodeBuffer, 0, compEnd); return; } } // Otherwise leave uncompressed: byte[] headerBuf = _headerBuffer; if (headerBuf == null) { _headerBuffer = headerBuf = new byte[LZFChunk.MAX_HEADER_LEN]; } LZFChunk.writeNonCompressedHeader(len, out, headerBuf); out.write(data, offset, len); }
/** * Method for encoding individual chunk, writing it to given output stream. */ public void encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out) throws IOException { if (len >= MIN_BLOCK_TO_COMPRESS) { // If we have non-trivial block, and can compress it by at least // 2 bytes (since header is 2 bytes longer), let's compress: int compEnd = tryCompress(data, offset, offset+len, _encodeBuffer, LZFChunk.HEADER_LEN_COMPRESSED); final int compLen = compEnd - LZFChunk.HEADER_LEN_COMPRESSED; if (compLen < (len-2)) { // yes, compressed block is smaller (consider header is 2 bytes longer) LZFChunk.appendCompressedHeader(len, compLen, _encodeBuffer, 0); out.write(_encodeBuffer, 0, compEnd); return; } } // Otherwise leave uncompressed: byte[] headerBuf = _headerBuffer; if (headerBuf == null) { _headerBuffer = headerBuf = new byte[LZFChunk.MAX_HEADER_LEN]; } LZFChunk.writeNonCompressedHeader(len, out, headerBuf); out.write(data, offset, len); }
/** * Method for encoding individual chunk, writing it to given output stream. */ public void encodeAndWriteChunk(byte[] data, int offset, int len, OutputStream out) throws IOException { if (len >= MIN_BLOCK_TO_COMPRESS) { // If we have non-trivial block, and can compress it by at least // 2 bytes (since header is 2 bytes longer), let's compress: int compEnd = tryCompress(data, offset, offset+len, _encodeBuffer, LZFChunk.HEADER_LEN_COMPRESSED); final int compLen = compEnd - LZFChunk.HEADER_LEN_COMPRESSED; if (compLen < (len-2)) { // yes, compressed block is smaller (consider header is 2 bytes longer) LZFChunk.appendCompressedHeader(len, compLen, _encodeBuffer, 0); out.write(_encodeBuffer, 0, compEnd); return; } } // Otherwise leave uncompressed: byte[] headerBuf = _headerBuffer; if (headerBuf == null) { _headerBuffer = headerBuf = new byte[LZFChunk.MAX_HEADER_LEN]; } LZFChunk.writeNonCompressedHeader(len, out, headerBuf); out.write(data, offset, len); }