Java Code Examples for net.jpountz.lz4.LZ4Factory#fastestInstance()
The following examples show how to use
net.jpountz.lz4.LZ4Factory#fastestInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lz4Compress.java From compress with MIT License | 6 votes |
@Override public byte[] uncompress(byte[] data) throws IOException { LZ4Factory factory = LZ4Factory.fastestInstance(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); LZ4FastDecompressor decompresser = factory.fastDecompressor(); LZ4BlockInputStream lzis = new LZ4BlockInputStream(new ByteArrayInputStream(data), decompresser); int count; byte[] buffer = new byte[2048]; while ((count = lzis.read(buffer)) != -1) { baos.write(buffer, 0, count); } lzis.close(); return baos.toByteArray(); }
Example 2
Source File: LZ4CompressorTest.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { if(args.length == 0){ System.out.println("args[0] must be data file path"); return; } LZ4Factory factory = LZ4Factory.fastestInstance(); byte[] data = Files.toByteArray(new File(args[0])); final int decompressedLength = data.length; // compress data LZ4Compressor compressor = factory.fastCompressor(); long start = System.currentTimeMillis(); int maxCompressedLength = compressor.maxCompressedLength(decompressedLength); byte[] compressed = new byte[maxCompressedLength]; int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength); System.out.println("compress take:" + (System.currentTimeMillis() - start)); System.out.println(compressedLength); // decompress data // - method 1: when the decompressed length is known LZ4FastDecompressor decompressor = factory.fastDecompressor(); start = System.currentTimeMillis(); byte[] restored = new byte[decompressedLength]; int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength); System.out.println("decompress take:" + (System.currentTimeMillis() - start)); System.out.println(decompressedLength); // compressedLength == compressedLength2 // - method 2: when the compressed length is known (a little slower) // the destination buffer needs to be over-sized LZ4SafeDecompressor decompressor2 = factory.safeDecompressor(); int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0); }
Example 3
Source File: Lz4FrameEncoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private Lz4FrameEncoder newEncoder(int blockSize, int maxEncodeSize) { Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum(); Lz4FrameEncoder encoder = new Lz4FrameEncoder(LZ4Factory.fastestInstance(), true, blockSize, checksum, maxEncodeSize); encoder.handlerAdded(ctx); return encoder; }
Example 4
Source File: Lz4Compress.java From compress with MIT License | 5 votes |
@Override public byte[] compress(byte[] data) throws IOException { LZ4Factory factory = LZ4Factory.fastestInstance(); ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); LZ4Compressor compressor = factory.fastCompressor(); LZ4BlockOutputStream compressedOutput = new LZ4BlockOutputStream(byteOutput, 2048, compressor); compressedOutput.write(data); compressedOutput.close(); return byteOutput.toByteArray(); }
Example 5
Source File: LZ4CompressorTest.java From kylin with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { if(args.length == 0){ System.out.println("args[0] must be data file path"); return; } LZ4Factory factory = LZ4Factory.fastestInstance(); byte[] data = Files.toByteArray(new File(args[0])); final int decompressedLength = data.length; // compress data LZ4Compressor compressor = factory.fastCompressor(); long start = System.currentTimeMillis(); int maxCompressedLength = compressor.maxCompressedLength(decompressedLength); byte[] compressed = new byte[maxCompressedLength]; int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength); System.out.println("compress take:" + (System.currentTimeMillis() - start)); System.out.println(compressedLength); // decompress data // - method 1: when the decompressed length is known LZ4FastDecompressor decompressor = factory.fastDecompressor(); start = System.currentTimeMillis(); byte[] restored = new byte[decompressedLength]; int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength); System.out.println("decompress take:" + (System.currentTimeMillis() - start)); System.out.println(decompressedLength); // compressedLength == compressedLength2 // - method 2: when the compressed length is known (a little slower) // the destination buffer needs to be over-sized LZ4SafeDecompressor decompressor2 = factory.safeDecompressor(); int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0); }
Example 6
Source File: SinParser.java From Flashtool with GNU General Public License v3.0 | 5 votes |
public String getDataTypePriv() throws IOException { RandomAccessFile fin = new RandomAccessFile(sinfile,"r"); byte[] res=null; byte[] rescomp=null; if (dataHeader.mmcfLen>0) { Object block = dataBlocks.firstElement(); if (block instanceof AddrBlock) { res = new byte[(int)((AddrBlock)block).dataLen]; fin.seek(getDataOffset()+((AddrBlock)block).dataOffset); fin.read(res); fin.close(); } else { rescomp = new byte[(int)((LZ4ABlock)block).compDataLen]; fin.seek(getDataOffset()+((LZ4ABlock)block).dataOffset); fin.read(rescomp); fin.close(); LZ4Factory factory = LZ4Factory.fastestInstance(); LZ4FastDecompressor decomp = factory.fastDecompressor(); res = decomp.decompress(rescomp, (int)((LZ4ABlock)block).uncompDataLen); } } else { res = new byte[blocks.blocks[0].length]; fin.seek(getDataOffset()); fin.read(res); fin.close(); } return getDataTypePriv(res); }
Example 7
Source File: NSO0Adapter.java From Ghidra-Switch-Loader with ISC License | 4 votes |
private void read() throws IOException { this.nso0 = new NSO0Header(this.fileReader, 0x0); LZ4Factory factory = LZ4Factory.fastestInstance(); LZ4FastDecompressor decompressor = factory.fastDecompressor(); NSO0SectionHeader textHeader = this.nso0.getSectionHeader(NXOSectionType.TEXT); NSO0SectionHeader rodataHeader = this.nso0.getSectionHeader(NXOSectionType.RODATA); NSO0SectionHeader dataHeader = this.nso0.getSectionHeader(NXOSectionType.DATA); int textOffset = textHeader.getMemoryOffset(); int rodataOffset = rodataHeader.getMemoryOffset(); int dataOffset = dataHeader.getMemoryOffset(); int textSize = textHeader.getDecompressedSize(); int rodataSize = rodataHeader.getDecompressedSize(); int dataSize = dataHeader.getDecompressedSize(); // The data section is last, so we use its offset + decompressed size byte[] full = new byte[dataOffset + dataSize]; byte[] decompressedText; byte[] decompressedRodata; byte[] decompressedData; if (this.nso0.isSectionCompressed(NXOSectionType.TEXT)) { byte[] compressedText = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.TEXT), this.nso0.getCompressedSectionSize(NXOSectionType.TEXT)); decompressedText = new byte[textSize]; decompressor.decompress(compressedText, decompressedText); } else { decompressedText = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.TEXT), textSize); } System.arraycopy(decompressedText, 0, full, textOffset, textSize); if (this.nso0.isSectionCompressed(NXOSectionType.RODATA)) { byte[] compressedRodata = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.RODATA), this.nso0.getCompressedSectionSize(NXOSectionType.RODATA)); decompressedRodata = new byte[rodataSize]; decompressor.decompress(compressedRodata, decompressedRodata); } else { decompressedRodata = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.RODATA), rodataSize); } System.arraycopy(decompressedRodata, 0, full, rodataOffset, rodataSize); if (this.nso0.isSectionCompressed(NXOSectionType.DATA)) { byte[] compressedData = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.DATA), this.nso0.getCompressedSectionSize(NXOSectionType.DATA)); decompressedData = new byte[dataSize]; decompressor.decompress(compressedData, decompressedData); } else { decompressedData = this.fileProvider.readBytes(this.nso0.getSectionFileOffset(NXOSectionType.DATA), dataSize); } System.arraycopy(decompressedData, 0, full, dataOffset, dataSize); this.memoryProvider = new ByteArrayProvider(full); this.sections = new NXOSection[3]; this.sections[NXOSectionType.TEXT.ordinal()] = new NXOSection(NXOSectionType.TEXT, textOffset, textSize); this.sections[NXOSectionType.RODATA.ordinal()] = new NXOSection(NXOSectionType.RODATA, rodataOffset, rodataSize); this.sections[NXOSectionType.DATA.ordinal()] = new NXOSection(NXOSectionType.DATA, dataOffset, dataSize); }
Example 8
Source File: ODAGPartLZ4Wrapper.java From Arabesque with Apache License 2.0 | 4 votes |
public ODAGPartLZ4Wrapper() { lz4factory = LZ4Factory.fastestInstance(); reset(); }
Example 9
Source File: ODAGStashLZ4Wrapper.java From Arabesque with Apache License 2.0 | 4 votes |
public ODAGStashLZ4Wrapper() { lz4factory = LZ4Factory.fastestInstance(); reset(); }
Example 10
Source File: LZ4ObjectCache.java From Arabesque with Apache License 2.0 | 4 votes |
public LZ4ObjectCache() { lz4factory = LZ4Factory.fastestInstance(); reset(); }
Example 11
Source File: LZ4Provider.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
public static LZ4Factory fastestInstance() { return IBM_FIX ? LZ4Factory.unsafeInstance() : LZ4Factory.fastestInstance(); }
Example 12
Source File: FrameCompressor.java From stratio-cassandra with Apache License 2.0 | 4 votes |
private LZ4Compressor() { final LZ4Factory lz4Factory = LZ4Factory.fastestInstance(); compressor = lz4Factory.fastCompressor(); decompressor = lz4Factory.decompressor(); }
Example 13
Source File: LZ4Compressor.java From stratio-cassandra with Apache License 2.0 | 4 votes |
private LZ4Compressor() { final LZ4Factory lz4Factory = LZ4Factory.fastestInstance(); compressor = lz4Factory.fastCompressor(); decompressor = lz4Factory.decompressor(); }
Example 14
Source File: Lz4FrameEncoder.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Creates a new LZ4 encoder with hight or fast compression, default block size (64 KB) * and xxhash hashing for Java, based on Yann Collet's work available at * <a href="https://github.com/Cyan4973/xxHash">Github</a>. * * @param highCompressor if {@code true} codec will use compressor which requires more memory * and is slower but compresses more efficiently * 基于Yann Collet在Github上的工作,为Java创建一个新的LZ4编码器,它具有较高或快速的压缩、默认块大小(64 KB)和xxhash散列。 */ public Lz4FrameEncoder(boolean highCompressor) { this(LZ4Factory.fastestInstance(), highCompressor, DEFAULT_BLOCK_SIZE, XXHashFactory.fastestInstance().newStreamingHash32(DEFAULT_SEED).asChecksum()); }
Example 15
Source File: Lz4FrameDecoder.java From netty-4.1.22 with Apache License 2.0 | 2 votes |
/** * Creates a LZ4 decoder with fastest decoder instance available on your machine.创建一个LZ4解码器,在您的机器上使用最快的解码器实例。 * * @param validateChecksums if {@code true}, the checksum field will be validated against the actual * uncompressed data, and if the checksums do not match, a suitable * {@link DecompressionException} will be thrown */ public Lz4FrameDecoder(boolean validateChecksums) { this(LZ4Factory.fastestInstance(), validateChecksums); }