本文整理汇总了Java中net.jpountz.lz4.LZ4Factory.fastCompressor方法的典型用法代码示例。如果您正苦于以下问题:Java LZ4Factory.fastCompressor方法的具体用法?Java LZ4Factory.fastCompressor怎么用?Java LZ4Factory.fastCompressor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.jpountz.lz4.LZ4Factory
的用法示例。
在下文中一共展示了LZ4Factory.fastCompressor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LZ4Compressor
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
private LZ4Compressor(String type, Integer compressionLevel)
{
this.compressorType = type;
this.compressionLevel = compressionLevel;
final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();
switch (type)
{
case LZ4_HIGH_COMPRESSOR:
{
compressor = lz4Factory.highCompressor(compressionLevel);
break;
}
case LZ4_FAST_COMPRESSOR:
default:
{
compressor = lz4Factory.fastCompressor();
}
}
decompressor = lz4Factory.fastDecompressor();
}
示例2: writeC
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
public void writeC(DataOutput out) throws IOException {
UnsafeByteArrayOutputStream outStream = new UnsafeByteArrayOutputStream();
outStream.writeInt(tables.entrySet().size());
for (Map.Entry<String, Table> entry : tables.entrySet())
{
String tableName = entry.getKey();
Table table = entry.getValue();
outStream.writeUTF(tableName);
table.write(outStream);
}
outStream.flush();
//WritableUtils.writeCompressedByteArray(out, outStream.toByteArray());
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4Compressor compressor = factory.fastCompressor();
byte[] outStreamByteArray = outStream.toByteArray();
int decompressedLength = outStreamByteArray.length;
int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
byte[] compressed = new byte[maxCompressedLength];
int compressedLength = compressor.compress(outStreamByteArray, 0, decompressedLength, compressed, 0, maxCompressedLength);
out.writeInt(decompressedLength);
out.writeInt(compressedLength);
out.write(compressed, 0, compressedLength);
outStream.close();
}
示例3: lz4
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
/**
* lz4 壓縮
*
* @param value
* @return
*/
public static byte[] lz4(byte[] value) {
byte[] result = new byte[0];
try {
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4Compressor compressor = factory.fastCompressor();
//
final int INTEGER_BYTES = 4;
int length = value.length;
int maxCompressedLength = compressor.maxCompressedLength(length);
byte[] buff = new byte[INTEGER_BYTES + maxCompressedLength];
// 用4個byte紀錄原始長度
buff[0] = (byte) (length >>> 24);
buff[1] = (byte) (length >>> 16);
buff[2] = (byte) (length >>> 8);
buff[3] = (byte) (length);
// 壓縮後長度
int written = compressor.compress(value, 0, length, buff, INTEGER_BYTES, maxCompressedLength);
// 新長度=4+壓縮後長度
int newLength = INTEGER_BYTES + written;
result = new byte[newLength];
System.arraycopy(buff, 0, result, 0, newLength);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
示例4: LZ4CompressionCodec
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
LZ4CompressionCodec(@Nonnegative final int bodyLength) {
if (bodyLength < 1 || bodyLength > MAX_BODY_LENGTH) {
throw new IllegalArgumentException("bodyLength < 1 || bodyLength > 0xFEEC: " + bodyLength);
}
final LZ4Factory factory = LZ4Factory.fastestInstance();
this.compressor = factory.fastCompressor();
this.decompressor = factory.fastDecompressor();
this.bodyLength = bodyLength;
this.headerLength = HEADER_LENGTH;
this.compressedLength = compressor.maxCompressedLength(bodyLength);
this.footerLength = FOOTER_LENGTH;
this.frameLength = headerLength + compressedLength + footerLength;
this.compressInput = new byte[this.bodyLength];
this.compressOutput = new byte[compressedLength];
this.decompressInput = new byte[compressedLength];
this.decompressOutput = new byte[this.bodyLength];
}
示例5: compress
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
@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();
}
示例6: compress
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
public static byte[] compress(byte srcBytes[]) throws IOException {
LZ4Factory factory = LZ4Factory.fastestInstance();
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
LZ4Compressor compressor = factory.fastCompressor();
LZ4BlockOutputStream compressedOutput = new LZ4BlockOutputStream(
byteOutput, 2048, compressor);
compressedOutput.write(srcBytes);
compressedOutput.close();
return byteOutput.toByteArray();
}
示例7: encodeAndCompressBody
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
protected void encodeAndCompressBody(ByteBuffer buffer, int startPosition) {
int startOfBody = buffer.position();
encodeBody(buffer);
setEncodedBody(buffer, startOfBody, buffer.position() - startOfBody);
length = buffer.position() - startPosition;
if (compressionLimit != 0 && length-4 > compressionLimit) {
byte[] compressedBody;
compressionType = CompressionType.LZ4;
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4Compressor compressor = factory.fastCompressor();
compressedBody = compressor.compress(encodedBody);
log.log(LogLevel.DEBUG, "Uncompressed size: " + encodedBody.length + ", Compressed size: " + compressedBody.length);
if (compressedBody.length + 4 < encodedBody.length) {
buffer.position(startPosition);
buffer.putInt(compressedBody.length + startOfBody - startPosition + 4 - 4); // +4 for compressed size
buffer.putInt(getCompressedCode(compressionType));
buffer.position(startOfBody);
buffer.putInt(encodedBody.length);
buffer.put(compressedBody);
buffer.limit(buffer.position());
return;
}
}
buffer.putInt(startPosition, length - 4); // Encoded length 4 less than actual length
buffer.limit(buffer.position());
}
示例8: LZ4Compressor
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
private LZ4Compressor()
{
final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();
compressor = lz4Factory.fastCompressor();
decompressor = lz4Factory.decompressor();
}
示例9: Lz4Compressor
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
public Lz4Compressor(boolean unsafe, int bufferSize, boolean useHC) {
super(bufferSize);
LZ4Factory factory = (unsafe) ? LZ4Factory.unsafeInstance() : LZ4Factory.safeInstance();
compressor = (useHC) ? factory.highCompressor() : factory.fastCompressor();
}
示例10: LZ4Compressor
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
private LZ4Compressor()
{
final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();
compressor = lz4Factory.fastCompressor();
decompressor = lz4Factory.fastDecompressor();
}
示例11: main
import net.jpountz.lz4.LZ4Factory; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
LZ4Factory factory = LZ4Factory.fastestInstance();
byte[] data = "Compressors and decompressors are interchangeable: it is perfectly correct to compress with the JNI bindings and to decompress with a Java port, or the other way around.Compressors might not generate the same compressed streams on all platforms, especially if CPU endianness differs, but the compressed streams can be safely decompressed by any decompressor implementation on any platform.Compressors and decompressors are interchangeable: it is perfectly correct to compress with the JNI bindings and to decompress with a Java port, or the other way around.Compressors might not generate the same compressed streams on all platforms, especially if CPU endianness differs, but the compressed streams can be safely decompressed by any decompressor implementation on any platform.".getBytes("UTF-8");
final int decompressedLength = data.length;
System.out.println("dataLength:" + decompressedLength);
// compress data
LZ4Compressor compressor = factory.fastCompressor();
int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
byte[] compressed = new byte[maxCompressedLength];
int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);
System.out.println("compressedLength:" + compressedLength);
// decompress data
// - method 1: when the decompressed length is known
LZ4FastDecompressor decompressor = factory.fastDecompressor();
byte[] restored = new byte[decompressedLength];
int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);
// compressedLength == compressedLength2
System.out.println("compressedLength2:" + 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);
// decompressedLength == decompressedLength2
System.out.println("decompressedLength2:" + compressedLength);
XXHashFactory factory1 = XXHashFactory.fastestInstance();
ByteArrayInputStream in = new ByteArrayInputStream(data);
int seed = 0x9747b28c; // used to initialize the hash value, use whatever
// value you want, but always the same
StreamingXXHash32 hash32 = factory1.newStreamingHash32(seed);
byte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes
for (;;) {
int read = in.read(buf);
if (read == -1) {
break;
}
hash32.update(buf, 0, read);
}
int hash = hash32.getValue();
System.out.println(hash);
}