public byte[] inflate(byte[] data) throws IOException { return LZFDecoder.decode(data); } }
public byte[] deflate(byte[] data) throws IOException { return LZFEncoder.encode(data); }
@Override public ByteBuffer allocateOutBuffer(int inputSize, Closer closer) { return ByteBuffer.allocate(LZFEncoder.estimateMaxWorkspaceSize(inputSize)); }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { final int length = in.readableBytes(); final int idx = in.readerIndex(); final byte[] input; final int inputPtr; if (in.hasArray()) { input = in.array(); inputPtr = in.arrayOffset() + idx; } else { input = recycler.allocInputBuffer(length); in.getBytes(idx, input, 0, length); inputPtr = 0; } final int maxOutputLength = LZFEncoder.estimateMaxWorkspaceSize(length); out.ensureWritable(maxOutputLength); final byte[] output = out.array(); final int outputPtr = out.arrayOffset() + out.writerIndex(); final int outputLength = LZFEncoder.appendEncoded(encoder, input, inputPtr, length, output, outputPtr) - outputPtr; out.writerIndex(out.writerIndex() + outputLength); in.skipBytes(length); if (!in.hasArray()) { recycler.releaseInputBuffer(input); } } }
private int _handleFiles(File dir) throws IOException { System.out.println("Testing files from dir '" + dir.getAbsolutePath() + "'..."); int count = 0; for(File f: dir.listFiles()) { if(f.isDirectory()) { count += _handleFiles(f); } else { byte[] data = _readData(f); byte[] enc = LZFEncoder.encode(data); byte[] dec = LZFDecoder.decode(enc); assertArrayEquals("File '" + f.getAbsolutePath() + "'", data, dec); ++count; } } return count; }
decoder.decodeChunk(inputArray, inPos, outputArray, outPos, outPos + originalLength); uncompressed.writerIndex(uncompressed.writerIndex() + originalLength); out.add(uncompressed);
@Override public ByteBuffer compress(ByteBuffer in, ByteBuffer out) { try (final ResourceHolder<BufferRecycler> bufferRecycler = CompressedPools.getBufferRecycler()) { int encodedLen = LZFEncoder.appendEncoded( in.array(), in.arrayOffset() + in.position(), in.remaining(), out.array(), out.arrayOffset(), bufferRecycler.get() ); out.clear(); out.limit(encodedLen); return out; } } }
public static int safeDecode(final byte[] sourceBuffer, int offset, int length, final byte[] targetBuffer) throws LZFException { return safeDecoder().decode(sourceBuffer, offset, length, targetBuffer); } }
public static int decode(final byte[] sourceBuffer, int offset, int length, final byte[] targetBuffer) throws LZFException { return fastDecoder().decode(sourceBuffer, offset, length, targetBuffer); }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { final int length = in.readableBytes(); final int idx = in.readerIndex(); final byte[] input; final int inputPtr; if (in.hasArray()) { input = in.array(); inputPtr = in.arrayOffset() + idx; } else { input = recycler.allocInputBuffer(length); in.getBytes(idx, input, 0, length); inputPtr = 0; } final int maxOutputLength = LZFEncoder.estimateMaxWorkspaceSize(length); out.ensureWritable(maxOutputLength); final byte[] output = out.array(); final int outputPtr = out.arrayOffset() + out.writerIndex(); final int outputLength = LZFEncoder.appendEncoded(encoder, input, inputPtr, length, output, outputPtr) - outputPtr; out.writerIndex(out.writerIndex() + outputLength); in.skipBytes(length); if (!in.hasArray()) { recycler.releaseInputBuffer(input); } } }
@Test public void test() throws IOException { byte[] raw = new byte[] { 1, 2, 3, 3, 2, 23 }; byte[] data = LZFEncoder.encode(raw); byte[] data2 = new byte[data.length * 2]; java.lang.System.arraycopy(data, 0, data2, 0, data.length); ImmutableBytesWritable bytes = new ImmutableBytesWritable(); bytes.set(data2, 0, data.length); try { byte[] uncompressed = LZFDecoder.decode(bytes.get(), bytes.getOffset(), bytes.getLength()); } catch (IOException e) { throw new RuntimeException("LZF decode failure", e); } } }
decoder.decodeChunk(inputArray, inPos, outputArray, outPos, outPos + originalLength); uncompressed.writerIndex(uncompressed.writerIndex() + originalLength); out.add(uncompressed);
@Override public void decompress(ByteBuffer in, int numBytes, ByteBuffer out) { final byte[] bytes = new byte[numBytes]; in.get(bytes); try (final ResourceHolder<byte[]> outputBytesHolder = CompressedPools.getOutputBytes()) { final byte[] outputBytes = outputBytesHolder.get(); final int numDecompressedBytes = LZFDecoder.decode(bytes, outputBytes); out.put(outputBytes, 0, numDecompressedBytes); out.flip(); } catch (IOException e) { throw new RuntimeException(e); } }
final String updatedBy = UUID.randomUUID().toString().substring(0, 4); final byte[] properties = LZFEncoder.encode(new byte[] { 'c', 'a', 'f', 'e' }); final String tableNameA = "test_database_export_dao_a"; final String tableNameB = "test_database_export_dao_b";
public static int safeDecode(final byte[] sourceBuffer, int offset, int length, final byte[] targetBuffer) throws LZFException { return safeDecoder().decode(sourceBuffer, offset, length, targetBuffer); } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { final int length = in.readableBytes(); final int idx = in.readerIndex(); final byte[] input; final int inputPtr; if (in.hasArray()) { input = in.array(); inputPtr = in.arrayOffset() + idx; } else { input = recycler.allocInputBuffer(length); in.getBytes(idx, input, 0, length); inputPtr = 0; } final int maxOutputLength = LZFEncoder.estimateMaxWorkspaceSize(length); out.ensureWritable(maxOutputLength); final byte[] output = out.array(); final int outputPtr = out.arrayOffset() + out.writerIndex(); final int outputLength = LZFEncoder.appendEncoded(encoder, input, inputPtr, length, output, outputPtr) - outputPtr; out.writerIndex(out.writerIndex() + outputLength); in.skipBytes(length); if (!in.hasArray()) { recycler.releaseInputBuffer(input); } } }
decoder.decodeChunk(inputArray, inPos, outputArray, outPos, outPos + originalLength); uncompressed.writerIndex(uncompressed.writerIndex() + originalLength); out.add(uncompressed);
public void fromBytes(ImmutableBytesWritable bytes) { try { uncompressed = LZFDecoder.decode(bytes.get(), bytes.getOffset(), bytes.getLength()); } catch (IOException e) { throw new RuntimeException("LZF decode failure", e); } size = cap = uncompressed.length / valueLen; compressed = BytesUtil.EMPTY_BYTE_ARRAY; // mark closed }
@Override public void closeForChange() { checkUpdateMode(); try { compressed = LZFEncoder.encode(uncompressed, 0, valueLen * size); } catch (Exception e) { throw new RuntimeException("LZF encode failure", e); } }
public static int safeDecode(final byte[] sourceBuffer, int offset, int length, final byte[] targetBuffer) throws LZFException { return safeDecoder().decode(sourceBuffer, offset, length, targetBuffer); } }