com.scudata.dw.LZ4Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.dw;
import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;
/**
* LZ4ѹ????ѹ??????
* @author runqian
*
*/
public class LZ4Util {
private static ThreadLocal local = new ThreadLocal() {
protected synchronized LZ4Util initialValue() {
return new LZ4Util();
}
};
//ѹ??
private LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
//??ѹ
private LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
private int count;
private LZ4Util() {
}
public static LZ4Util instance() {
return local.get();
}
/**
* ????ѹ????ij???
* @return
*/
public int getCount() {
return count;
}
/**
* ????ѹ??????ֽ????飬?ֽ????鳤?ȿ??ܴ???ʵ?ʳ??ȣ???Ҫ????getCountȡ??ʵ?ʳ???
* @param bytes
* @return
*/
public byte[] compress(byte []bytes) {
int maxLen = compressor.maxCompressedLength(bytes.length);
byte []buffer = new byte[maxLen];
count = compressor.compress(bytes, buffer);
return buffer;
}
/**
* ??ѹ??srcCountΪ??ѹ??
* @param bytes
* @param buffer
* @param srcCount
*/
public void decompress(byte []bytes, byte []buffer, int srcCount) {
decompressor.decompress(bytes, buffer, srcCount);
}
public void decompress(byte []bytes, int offset, byte []buffer, int srcCount) {
decompressor.decompress(bytes, offset, buffer, 0, srcCount);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy