org.xerial.snappy.Snappy.maxCompressedLength()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中org.xerial.snappy.Snappy.maxCompressedLength()方法的一些代码示例,展示了Snappy.maxCompressedLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snappy.maxCompressedLength()方法的具体详情如下:
包路径:org.xerial.snappy.Snappy
类名称:Snappy
方法名:maxCompressedLength

Snappy.maxCompressedLength介绍

[英]Get the maximum byte size needed for compressing data of the given byte size.
[中]获取压缩给定字节大小的数据所需的最大字节大小。

代码示例

代码示例来源:origin: redisson/redisson

private boolean hasSufficientOutputBufferFor(int inputSize)
{
  int maxCompressedSize = Snappy.maxCompressedLength(inputSize);
  return maxCompressedSize < outputBuffer.length - outputCursor - 4;
}

代码示例来源:origin: redisson/redisson

/**
 * Compress the input data and produce a byte array of the uncompressed data
 *
 * @param data input array. The input MUST be an array type
 * @param byteSize the input byte size
 * @return compressed data
 */
public static byte[] rawCompress(Object data, int byteSize)
    throws IOException
{
  byte[] buf = new byte[Snappy.maxCompressedLength(byteSize)];
  int compressedByteSize = impl.rawCompress(data, 0, byteSize, buf, 0);
  byte[] result = new byte[compressedByteSize];
  System.arraycopy(buf, 0, result, 0, compressedByteSize);
  return result;
}

代码示例来源:origin: apache/avro

@Override ByteBuffer compress(ByteBuffer in) throws IOException {
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining()));
 int size = Snappy.compress(in.array(), in.position(), in.remaining(),
               out.array(), 0);
 out.limit(size);
 return out;
}

代码示例来源:origin: org.apache.avro/avro

@Override
public ByteBuffer compress(ByteBuffer in) throws IOException {
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
 int size = Snappy.compress(in.array(), in.position(), in.remaining(),
               out.array(), 0);
 crc32.reset();
 crc32.update(in.array(), in.position(), in.remaining());
 out.putInt(size, (int)crc32.getValue());
 out.limit(size+4);
 return out;
}

代码示例来源:origin: redisson/redisson

/**
 * @param size
 */
private void allocateBuffersBasedOnSize(int size)
{
  if (input != null) {
    releaseDirectByteBuffer(input);
  }
  if (uncompressedDirect != null) {
    releaseDirectByteBuffer(uncompressedDirect);
  }
  input = ByteBuffer.allocateDirect(size);
  final int maxCompressedLength = Snappy.maxCompressedLength(size);
  uncompressedDirect = ByteBuffer.allocateDirect(maxCompressedLength);
  buffer = new byte[maxCompressedLength];
}

代码示例来源:origin: apache/avro

@Override
public ByteBuffer compress(ByteBuffer in) throws IOException {
 int offset = computeOffset(in);
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
 int size = Snappy.compress(in.array(), offset, in.remaining(),
               out.array(), 0);
 crc32.reset();
 crc32.update(in.array(), offset, in.remaining());
 out.putInt(size, (int)crc32.getValue());
 out.limit(size+4);
 return out;
}

代码示例来源:origin: redisson/redisson

directInputBuffer = ByteBuffer.allocateDirect(blockSize);
outputBuffer = ByteBuffer.allocateDirect(Snappy
    .maxCompressedLength(blockSize));

代码示例来源:origin: redisson/redisson

public SnappyOutputStream(OutputStream out, int blockSize, BufferAllocatorFactory bufferAllocatorFactory)
{
  this.out = out;
  this.blockSize = Math.max(MIN_BLOCK_SIZE, blockSize);
  int inputSize = blockSize;
  int outputSize = SnappyCodec.HEADER_SIZE + 4 + Snappy.maxCompressedLength(blockSize);
  this.inputBufferAllocator = bufferAllocatorFactory.getBufferAllocator(inputSize);
  this.outputBufferAllocator = bufferAllocatorFactory.getBufferAllocator(outputSize);
  inputBuffer = inputBufferAllocator.allocate(inputSize);
  outputBuffer = outputBufferAllocator.allocate(outputSize);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void compress(final List<ByteBuf> source, final BsonOutput target) {
  int uncompressedSize = getUncompressedSize(source);
  byte[] singleByteArraySource = new byte[uncompressedSize];
  copy(source, singleByteArraySource);
  try {
    byte[] out = new byte[Snappy.maxCompressedLength(uncompressedSize)];
    int compressedSize = Snappy.compress(singleByteArraySource, 0, singleByteArraySource.length, out, 0);
    target.writeBytes(out, 0, compressedSize);
  } catch (IOException e) {
    throw new MongoInternalException("Unexpected IOException", e);
  }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

private ByteBuf compressHeap(ByteBuf input) throws IOException {
 int maxCompressedLength = Snappy.maxCompressedLength(input.readableBytes());
 int inOffset = input.arrayOffset() + input.readerIndex();
 byte[] in = input.array();
 int len = input.readableBytes();
 // Increase reader index.
 input.readerIndex(input.writerIndex());
 // Allocate a heap buffer from the ByteBufAllocator as we may use a PooledByteBufAllocator and
 // so
 // can eliminate the overhead of allocate a new byte[].
 ByteBuf output = input.alloc().heapBuffer(maxCompressedLength);
 try {
  // Calculate the correct offset.
  int offset = output.arrayOffset() + output.writerIndex();
  byte[] out = output.array();
  int written = Snappy.compress(in, inOffset, len, out, offset);
  // Increase the writerIndex with the written bytes.
  output.writerIndex(output.writerIndex() + written);
 } catch (IOException e) {
  // release output buffer so we not leak and rethrow exception.
  output.release();
  throw e;
 }
 return output;
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

private ByteBuf compressDirect(ByteBuf input) throws IOException {
 int maxCompressedLength = Snappy.maxCompressedLength(input.readableBytes());
 // If the input is direct we will allocate a direct output buffer as well as this will allow us
 // to use
 // Snappy.compress(ByteBuffer, ByteBuffer) and so eliminate memory copies.
 ByteBuf output = input.alloc().directBuffer(maxCompressedLength);
 try {
  ByteBuffer in = inputNioBuffer(input);
  // Increase reader index.
  input.readerIndex(input.writerIndex());
  ByteBuffer out = outputNioBuffer(output);
  int written = Snappy.compress(in, out);
  // Set the writer index so the amount of written bytes is reflected
  output.writerIndex(output.writerIndex() + written);
 } catch (IOException e) {
  // release output buffer so we not leak and rethrow exception.
  output.release();
  throw e;
 }
 return output;
}

代码示例来源:origin: forcedotcom/phoenix

int maxCompressedSize = Snappy.maxCompressedLength(baOut.size());
byte[] compressed = new byte[maxCompressedSize]; // size for worst case
int compressedSize = Snappy.compress(baOut.getBuffer(), 0, baOut.size(), compressed, 0);

代码示例来源:origin: spotify/sparkey-java

SnappyRandomReader(BlockRandomInput data, int maxBlockSize) {
 this.data = data;
 this.maxBlockSize = maxBlockSize;
 blockSize = 0;
 bufPos = 0;
 uncompressedBuf = new byte[maxBlockSize];
 compressedBuf = new byte[Snappy.maxCompressedLength(maxBlockSize)];
}

代码示例来源:origin: thulab/tsfile

@Override
public int getMaxBytesForCompression(int uncompressedDataSize) {
  return Snappy.maxCompressedLength(uncompressedDataSize);
}

代码示例来源:origin: com.spotify.sparkey/sparkey

public SnappyReader(InputStream data, int maxBlockSize, long start) {
 this.data = data;
 blockSize = 0;
 bufPos = 0;
 curBlockStart = start;
 nextBlockStart = start;
 uncompressedBuf = new byte[maxBlockSize];
 compressedBuf = new byte[Snappy.maxCompressedLength(maxBlockSize)];
}

代码示例来源:origin: io.github.pcmind/leveldb

@Override
  public int maxCompressedLength(int length)
  {
    return org.xerial.snappy.Snappy.maxCompressedLength(length);
  }
}

代码示例来源:origin: com.spotify.sparkey/sparkey

SnappyOutputStream(int maxBlockSize, OutputStream output, FileDescriptor fileDescriptor) throws IOException {
 this.fileDescriptor = fileDescriptor;
 if (maxBlockSize < 10) {
  throw new IOException("Too small block size - won't be able to fit keylen + valuelen in a single block");
 }
 this.maxBlockSize = maxBlockSize;
 this.output = output;
 uncompressedBuffer = new byte[maxBlockSize];
 compressedBuffer = new byte[Snappy.maxCompressedLength(maxBlockSize)];
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.avro

@Override
public ByteBuffer compress(ByteBuffer in) throws IOException {
 ByteBuffer out =
  ByteBuffer.allocate(Snappy.maxCompressedLength(in.remaining())+4);
 int size = Snappy.compress(in.array(), in.position(), in.remaining(),
               out.array(), 0);
 crc32.reset();
 crc32.update(in.array(), in.position(), in.remaining());
 out.putInt(size, (int)crc32.getValue());
 out.limit(size+4);
 return out;
}

代码示例来源:origin: com.baidu/brpc-java

@Override
public ByteBuf compressOutput(Object proto, RpcMethodInfo rpcMethodInfo) throws IOException {
  byte[] bytes = rpcMethodInfo.outputEncode(proto);
  int maxCompressedSize = Snappy.maxCompressedLength(bytes.length);
  byte[] compressedBytes = new byte[maxCompressedSize];
  int compressedLen = Snappy.compress(bytes, 0, bytes.length, compressedBytes, 0);
  return Unpooled.wrappedBuffer(compressedBytes, 0, compressedLen);
}

代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core

public Frame compress(Frame frame) throws IOException {
  byte[] input = CBUtil.readRawBytes(frame.body);
  byte[] output = new byte[Snappy.maxCompressedLength(input.length)];
  int written = Snappy.compress(input, 0, input.length, output, 0);
  return frame.with(ChannelBuffers.wrappedBuffer(output, 0, written));
}

相关文章