本文整理汇总了Java中net.jpountz.lz4.LZ4Factory类的典型用法代码示例。如果您正苦于以下问题:Java LZ4Factory类的具体用法?Java LZ4Factory怎么用?Java LZ4Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LZ4Factory类属于net.jpountz.lz4包,在下文中一共展示了LZ4Factory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:22,代码来源:LZ4Compressor.java
示例2: uncompress
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
@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();
}
开发者ID:yu120,项目名称:compress,代码行数:17,代码来源:Lz4Compress.java
示例3: readFieldsC
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
public void readFieldsC(DataInput in) throws IOException {
int decompressedLength = in.readInt();
int compressedLength = in.readInt();
byte[] compressed = new byte[compressedLength];
in.readFully(compressed, 0, compressedLength);
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
byte[] uncompressedByteArray = new byte[decompressedLength];
decompressor.decompress(compressed, 0, uncompressedByteArray, 0, decompressedLength);
//byte[] uncompressedByteArray = WritableUtils.readCompressedByteArray(in);
UnsafeByteArrayInputStream inStream = new UnsafeByteArrayInputStream(uncompressedByteArray);
size = inStream.readInt();
tables = new HashMap<String, Table>();
for (int i = 0; i < size; i++)
{
String tableName = inStream.readUTF();
Table table = new Table(null, null);
table.readFields(inStream);
tables.put(tableName, table);
}
}
开发者ID:wmoustafa,项目名称:granada,代码行数:23,代码来源:Database.java
示例4: 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();
}
开发者ID:wmoustafa,项目名称:granada,代码行数:25,代码来源:Database.java
示例5: onDeserialize
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
@Override
protected void onDeserialize(Deserializer buf) {
super.onDeserialize(buf);
int length = buf.getInt(null);
int compressedLength = buf.getInt(null);
Preconditions.checkState(length == data.length,
"Size of serialized sketch does not match expected value. Expected %s, actual %s.", data.length, length);
if (length == compressedLength) {
deserializeDataArray(data, length, buf);
} else {
LZ4FastDecompressor c = LZ4Factory.safeInstance().fastDecompressor();
byte[] compressedData = buf.getBytes(null, compressedLength);
c.decompress(compressedData, data);
}
}
开发者ID:vespa-engine,项目名称:vespa,代码行数:17,代码来源:NormalSketch.java
示例6: print
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
private void print(Request request) {
Values ret = request.returnValues();
CompressionType type = CompressionType.valueOf(ret.get(0).asInt8());
int uncompressedSize = ret.get(1).asInt32();
byte [] blob = ret.get(2).asData();
if (type == CompressionType.LZ4) {
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
byte [] uncompressed = new byte [uncompressedSize];
int compressedLength = decompressor.decompress(blob, 0, uncompressed, 0, uncompressedSize);
if (compressedLength != blob.length) {
throw new DeserializationException("LZ4 decompression failed. compressed size does not match. Expected " + blob.length + ". Got " + compressedLength);
}
blob = uncompressed;
}
Slime slime = BinaryFormat.decode(blob);
try {
new JsonFormat(true).encode(System.out, slime);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:vespa-engine,项目名称:vespa,代码行数:23,代码来源:VespaSummaryBenchmark.java
示例7: unlz4
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
/**
* lz4 解壓縮
*
* @param value
* @return
*/
public static byte[] unlz4(byte[] value) {
byte[] result = new byte[0];
try {
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
//
final int INTEGER_BYTES = 4;
// 取原始長度
int uncompressedLength = ((value[0] & 0xFF) << 24) | ((value[1] & 0xFF) << 16) | ((value[2] & 0xFF) << 8)
| ((value[3] & 0xFF));
result = new byte[uncompressedLength];
int read = decompressor.decompress(value, INTEGER_BYTES, result, 0, uncompressedLength);
if (read != (value.length - INTEGER_BYTES)) {
result = new byte[0];
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:27,代码来源:CompressHelperWithoutPool.java
示例8: 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;
}
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:34,代码来源:CompressHelper.java
示例9: 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];
}
开发者ID:ricardopadilha,项目名称:dsys-snio,代码行数:20,代码来源:LZ4CompressionCodec.java
示例10: CompressedImage
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
public CompressedImage(BufferedImage img, CompressedType type) {
this.width = img.getWidth();
this.height = img.getHeight();
this.type = type;
switch (type) {
case PNG:
this.data = ImageUtils.toPNG(img);
this.uncompressedLength = -1;
break;
case LZ4:
byte[] uncompressed = getUncompressedBytes(img);
this.uncompressedLength = uncompressed.length;
this.data = LZ4Factory.unsafeInstance().fastCompressor().compress(uncompressed);
break;
default:
throw new IllegalArgumentException();
}
}
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:23,代码来源:CompressedImage.java
示例11: get
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
public Image get() {
switch (type) {
case PNG:
return ImageUtils.fromPNG(data);
case LZ4:
LZ4FastDecompressor lz4Decompressor = LZ4Factory.unsafeInstance().fastDecompressor();
byte[] uncompressed = new byte[uncompressedLength];
lz4Decompressor.decompress(data, uncompressed);
return uncompressImage(width, height, uncompressed);
// byte[]decompressed = lz4Decompressor.d
// case LZ4:
// return LZ4Factory.unsafeInstance().fastCompressor().compress(getUncompressedBytes(img));
//
default:
throw new IllegalArgumentException();
}
}
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:19,代码来源:CompressedImage.java
示例12: 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();
}
开发者ID:yu120,项目名称:compress,代码行数:12,代码来源:Lz4Compress.java
示例13: KafkaLZ4BlockOutputStream
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
/**
* Create a new {@link OutputStream} that will compress data using the LZ4 algorithm.
*
* @param out The output stream to compress
* @param blockSize Default: 4. The block size used during compression. 4=64kb, 5=256kb, 6=1mb, 7=4mb. All other
* values will generate an exception
* @param blockChecksum Default: false. When true, a XXHash32 checksum is computed and appended to the stream for
* every block of data
* @param useBrokenFlagDescriptorChecksum Default: false. When true, writes an incorrect FrameDescriptor checksum
* compatible with older kafka clients.
* @throws IOException
*/
public KafkaLZ4BlockOutputStream(OutputStream out, int blockSize, boolean blockChecksum, boolean useBrokenFlagDescriptorChecksum) throws IOException {
super(out);
compressor = LZ4Factory.fastestInstance().fastCompressor();
checksum = XXHashFactory.fastestInstance().hash32();
this.useBrokenFlagDescriptorChecksum = useBrokenFlagDescriptorChecksum;
bd = new BD(blockSize);
flg = new FLG(blockChecksum);
bufferOffset = 0;
maxBlockSize = bd.getBlockMaximumSize();
buffer = new byte[maxBlockSize];
compressedBuffer = new byte[compressor.maxCompressedLength(maxBlockSize)];
finished = false;
writeHeader();
}
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:27,代码来源:KafkaLZ4BlockOutputStream.java
示例14: 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();
}
开发者ID:Lazyeraser,项目名称:DereHelper,代码行数:11,代码来源:LZ4Helper.java
示例15: uncompress
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
public static byte[] uncompress(byte[] bytes) throws IOException {
LZ4Factory factory = LZ4Factory.fastestInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LZ4FastDecompressor decompresser = factory.fastDecompressor();
LZ4BlockInputStream lzis = new LZ4BlockInputStream(
new ByteArrayInputStream(bytes), decompresser);
int count;
byte[] buffer = new byte[2048 * 256];
while ((count = lzis.read(buffer)) != -1) {
baos.write(buffer, 0, count);
}
lzis.close();
return baos.toByteArray();
}
开发者ID:Lazyeraser,项目名称:DereHelper,代码行数:16,代码来源:LZ4Helper.java
示例16: uncompressCGSS
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
public static byte[] uncompressCGSS(byte[] src) throws IOException {
byte[] buf = new byte[4];
System.arraycopy(src, 4, buf, 0, 4);
int destL = getInt(buf, 0);
byte[] source = new byte[src.length - 16];
byte[] dest = new byte[destL];
System.arraycopy(src, 16, source, 0, src.length - 16);
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompresser = factory.fastDecompressor();
decompresser.decompress(source, dest, destL);
return dest;
}
开发者ID:Lazyeraser,项目名称:DereHelper,代码行数:16,代码来源:LZ4Helper.java
示例17: KafkaLZ4BlockInputStream
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
/**
* Create a new {@link InputStream} that will decompress data using the LZ4 algorithm.
*
* @param in The stream to decompress
* @param ignoreFlagDescriptorChecksum for compatibility with old kafka clients, ignore incorrect HC byte
* @throws IOException
*/
public KafkaLZ4BlockInputStream(InputStream in, boolean ignoreFlagDescriptorChecksum) throws IOException {
super(in);
decompressor = LZ4Factory.fastestInstance().safeDecompressor();
checksum = XXHashFactory.fastestInstance().hash32();
this.ignoreFlagDescriptorChecksum = ignoreFlagDescriptorChecksum;
readHeader();
maxBlockSize = bd.getBlockMaximumSize();
buffer = new byte[maxBlockSize];
compressedBuffer = new byte[maxBlockSize];
bufferOffset = 0;
bufferSize = 0;
finished = false;
}
开发者ID:txazo,项目名称:kafka,代码行数:21,代码来源:KafkaLZ4BlockInputStream.java
示例18: 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());
}
开发者ID:vespa-engine,项目名称:vespa,代码行数:29,代码来源:BasicPacket.java
示例19: LZ4FrameInputStream
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
/**
* Create a new {@link InputStream} that will decompress data using the LZ4 algorithm.
*
* @param in The stream to decompress
* @throws IOException
*/
public LZ4FrameInputStream(InputStream in) throws IOException {
super(in);
decompressor = LZ4Factory.fastestInstance().safeDecompressor();
checksum = XXHashFactory.fastestInstance().hash32();
nextFrameInfo();
}
开发者ID:htools,项目名称:htools,代码行数:13,代码来源:LZ4FrameInputStream.java
示例20: KafkaLZ4BlockOutputStream
import net.jpountz.lz4.LZ4Factory; //导入依赖的package包/类
/**
* Create a new {@link OutputStream} that will compress data using the LZ4 algorithm.
*
* @param out The output stream to compress
* @param blockSize Default: 4. The block size used during compression. 4=64kb, 5=256kb, 6=1mb, 7=4mb. All other
* values will generate an exception
* @param blockChecksum Default: false. When true, a XXHash32 checksum is computed and appended to the stream for
* every block of data
* @param useBrokenFlagDescriptorChecksum Default: false. When true, writes an incorrect FrameDescriptor checksum
* compatible with older kafka clients.
* @throws IOException
*/
public KafkaLZ4BlockOutputStream( OutputStream out, int blockSize, boolean blockChecksum, boolean useBrokenFlagDescriptorChecksum ) throws IOException {
super( out );
compressor = LZ4Factory.fastestInstance().highCompressor( 17 );
checksum = XXHashFactory.fastestInstance().hash32();
this.useBrokenFlagDescriptorChecksum = useBrokenFlagDescriptorChecksum;
bd = new BD( blockSize );
flg = new FLG( blockChecksum );
bufferOffset = 0;
maxBlockSize = bd.getBlockMaximumSize();
buffer = new byte[maxBlockSize];
compressedBuffer = new byte[compressor.maxCompressedLength( maxBlockSize )];
finished = false;
writeHeader();
}
开发者ID:oaplatform,项目名称:oap,代码行数:27,代码来源:KafkaLZ4BlockOutputStream.java
注:本文中的net.jpountz.lz4.LZ4Factory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论