本文整理汇总了Java中org.iq80.snappy.Snappy.maxCompressedLength方法的典型用法代码示例。如果您正苦于以下问题:Java Snappy.maxCompressedLength方法的具体用法?Java Snappy.maxCompressedLength怎么用?Java Snappy.maxCompressedLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.iq80.snappy.Snappy
的用法示例。
在下文中一共展示了Snappy.maxCompressedLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressSnappy
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
public static byte[] compressSnappy(final BlockValue bv, final FTableDescriptor td) {
byte[] bytes = null;
final int totalSize = bv.getValueSize() + (bv.size() * 4);
try (HeapDataOutputStream hdos = new HeapDataOutputStream(totalSize, null, true)) {
for (final byte[] rec : bv.getRecords()) {
hdos.writeInt(rec.length);
hdos.write(rec);
}
// bytes = Snappy.compress(hdos.toByteArray());
bytes = hdos.toByteArray();
byte[] compressedOut = new byte[Snappy.maxCompressedLength(bytes.length)];
int compressedSize = Snappy.compress(bytes, 0, bytes.length, compressedOut, 0);
bytes = Arrays.copyOf(compressedOut, compressedSize);
} catch (IOException e) {
logger.error("Error converting to Snappy format.", e);
}
return bytes;
}
示例2: writeBlock
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
private void writeBlock(BlockBuilder block, TableFormat.BlockHandle handle) throws IOException {
Slice raw = block.finish();
Slice blockContents;
int type = options.compression;
switch (type) {
case Options.CompressionType.NO_COMPRESSION:
blockContents = raw;
break;
case Options.CompressionType.SNAPPY_COMPRESSION:
int maxLength = Snappy.maxCompressedLength(raw.data().length);
if (maxLength > compressBuffer.length) {
compressBuffer = new byte[maxLength * 2];
}
int compressLength = Snappy.compress(raw.data(), 0, raw.size(), compressBuffer, 0);
if (compressLength < raw.size() - raw.size() / 8) {
blockContents = new Slice(Arrays.copyOf(compressBuffer, compressLength));
} else {
blockContents = raw;
type = Options.CompressionType.NO_COMPRESSION;
}
break;
default:
throw new IOException("Compression type not supported");
}
writeRawBlock(blockContents, type, handle);
block.reset();
}
示例3: compressBytes
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
public static byte[] compressBytes(byte[] bytesArray) {
int decompressedLength = bytesArray.length;
int maxCompressedLength = Snappy.maxCompressedLength(decompressedLength);
byte[] compressed = new byte[maxCompressedLength];
int compressedLength = Snappy.compress(bytesArray, 0, decompressedLength, compressed, 0);
byte[] truncated = Arrays.copyOfRange(compressed, 0, compressedLength );
byte[] checkSumExt = Arrays.copyOf(truncated, truncated.length+8);
Adler32 adler32 = new Adler32();
adler32.update(truncated);
long checkSum =adler32.getValue();
ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
byte[] checkSumBuf =buffer.putLong(checkSum).array();
checkSumExt[truncated.length] = checkSumBuf[0];
checkSumExt[truncated.length+1] = checkSumBuf[1];
checkSumExt[truncated.length+2] = checkSumBuf[2];
checkSumExt[truncated.length+3] = checkSumBuf[3];
checkSumExt[truncated.length+4] = checkSumBuf[4];
checkSumExt[truncated.length+5] = checkSumBuf[5];
checkSumExt[truncated.length+6] = checkSumBuf[6];
checkSumExt[truncated.length+7] = checkSumBuf[7];
return checkSumExt;
}
示例4: getMaxCompressedLength
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
private int getMaxCompressedLength(int bufferSize) {
try {
return Snappy.maxCompressedLength(bufferSize);
} catch(Exception e) {
return bufferSize;
}
}
示例5: maxCompressedLength
import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
static int maxCompressedLength(int byteSize) throws IOException {
return Snappy.maxCompressedLength(byteSize);
}