当前位置: 首页>>代码示例>>Java>>正文


Java Snappy.maxCompressedLength方法代码示例

本文整理汇总了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;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:OrcUtils.java

示例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();
}
 
开发者ID:zxl0714,项目名称:leveldb-sstable,代码行数:29,代码来源:TableBuilder.java

示例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;
}
 
开发者ID:PortfolioEffect,项目名称:PE-HFT-Java,代码行数:29,代码来源:ArrayUtil.java

示例4: getMaxCompressedLength

import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
private int getMaxCompressedLength(int bufferSize) {
    try {
        return Snappy.maxCompressedLength(bufferSize);
    } catch(Exception e) {
        return bufferSize;
    }
}
 
开发者ID:tootedom,项目名称:tomcat-memcached-response-filter,代码行数:8,代码来源:SerializingTranscoder.java

示例5: maxCompressedLength

import org.iq80.snappy.Snappy; //导入方法依赖的package包/类
static int maxCompressedLength(int byteSize) throws IOException {
  return Snappy.maxCompressedLength(byteSize);
}
 
开发者ID:apache,项目名称:tajo,代码行数:4,代码来源:CompressionUtil.java


注:本文中的org.iq80.snappy.Snappy.maxCompressedLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。