public byte[] inflate(byte[] data) throws IOException { return LZFDecoder.decode(data); } }
@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); } }
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; }
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 }
@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); } } }
public static byte[] decompress(byte[] in) throws IOException { return LZFDecoder.decode(in); }
public byte[] uncompress(byte[] target) { try { return LZFDecoder.decode(target); } catch (LZFException e) { throw new RuntimeException(e); } }
public String uncompressString(byte[] target) { try { byte[] sourceBytes = LZFDecoder.decode(target); return new String(sourceBytes); } catch (LZFException e) { throw new RuntimeException(e); } }
public String uncompressString(byte[] target, Charset charset) { try { byte[] sourceBytes = LZFDecoder.decode(target); return new String(sourceBytes, charset); } catch (LZFException e) { throw new RuntimeException(e); } }
@Override public RevObject read(@Nullable ObjectId id, byte[] data, int offset, int length) throws IOException { byte[] decoded = LZFDecoder.decode(data, offset, length); return factory.read(id, decoded, 0, decoded.length); }
@Override public RevObject read(@Nullable ObjectId id, byte[] data, int offset, int length) throws IOException { byte[] decoded = LZFDecoder.decode(data, offset, length); return factory.read(id, decoded, 0, decoded.length); }
@Override protected String dbTypeToValue(Blob dbValue) throws SQLException { try { if (dbValue != null) { byte[] blobBytes = dbValue.getBytes(1L, (int) dbValue.length()); // make best guess whether value was previously compressed with LZF if ((blobBytes.length > 0) && (blobBytes[0] == LZFChunk.BYTE_Z) && (blobBytes[1] == LZFChunk.BYTE_V)) { byte[] decodedBytes = LZFDecoder.decode(blobBytes); return new String(decodedBytes, StandardCharsets.UTF_8); } else { return new String(blobBytes, StandardCharsets.UTF_8); } } else { return null; } } catch (LZFException ex) { //Couldn't deal with the data throw new SQLException(ex); } }
@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); } }
@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); } }
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 }
int numDecompressedBytes = LZFDecoder.decode(bytes, outputBytes); buf.put(outputBytes, 0, numDecompressedBytes); buf.flip();