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

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

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

Snappy.compress介绍

[英]Compress the input String
[中]压缩输入字符串

代码示例

代码示例来源:origin: apache/incubator-pinot

@Override
 public int compress(ByteBuffer inDecompressed, ByteBuffer outCompressed)
   throws IOException {
  return Snappy.compress(inDecompressed, outCompressed);
 }
}

代码示例来源:origin: tjake/Solandra

public static byte[] compress(byte[] input) throws IOException
{
  if(!useCompression)
    return input;      
    return Snappy.compress(input);          
}

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

/**
 * Compress the input string using the given encoding
 *
 * @param s
 * @param encoding
 * @return the compressed data
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
public static byte[] compress(String s, String encoding)
    throws UnsupportedEncodingException, IOException
{
  byte[] data = s.getBytes(encoding);
  return compress(data);
}

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

/**
 * Compress the input string using the given encoding
 *
 * @param s
 * @param encoding
 * @return the compressed data
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
public static byte[] compress(String s, Charset encoding)
    throws IOException
{
  byte[] data = s.getBytes(encoding);
  return compress(data);
}

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

/**
 * Compress the input String
 *
 * @param s
 * @return the compressed data
 * @throws IOException
 */
public static byte[] compress(String s)
    throws IOException
{
  try {
    return compress(s, "UTF-8");
  }
  catch (UnsupportedEncodingException e) {
    throw new IllegalStateException("UTF-8 encoder is not found");
  }
}

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

@Override
public void writeValueToBuffer(DataOutput buffer) throws IOException
{
  byte[] compressedBytes = Snappy.compress(m_value);
  buffer.writeShort(compressedBytes.length);
  buffer.write(compressedBytes);
}

代码示例来源: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: 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

Snappy.compress(directInputBuffer, outputBuffer);

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

/**
 * @param compactPage Compacted page.
 * @param compactSize Compacted page size.
 * @return Compressed page.
 */
private ByteBuffer compressPageSnappy(ByteBuffer compactPage, int compactSize) {
  ByteBuffer compressedPage = compressBuf.get();
  copyPageHeader(compactPage, compressedPage, compactSize);
  try {
    int compressedSize = Snappy.compress(compactPage, compressedPage);
    assert compressedPage.limit() == PageIO.COMMON_HEADER_END + compressedSize;
  }
  catch (IOException e) {
    throw new IgniteException("Failed to compress page with Snappy.", e);
  }
  compactPage.position(0);
  compressedPage.position(0);
  return compressedPage;
}

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

protected void compressInput()
    throws IOException
{
  if (inputCursor <= 0) {
    return; // no need to dump
  }
  if (!headerWritten) {
    outputCursor = writeHeader();
    headerWritten = true;
  }
  // Compress and dump the buffer content
  if (!hasSufficientOutputBufferFor(inputCursor)) {
    dumpOutput();
  }
  writeBlockPreemble();
  int compressedSize = Snappy.compress(inputBuffer, 0, inputCursor, outputBuffer, outputCursor + 4);
  // Write compressed data size
  writeInt(outputBuffer, outputCursor, compressedSize);
  outputCursor += 4 + compressedSize;
  inputCursor = 0;
}

代码示例来源: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: palantir/atlasdb

public static byte[] compressWithSnappy(byte[] bytes) {
  try {
    return Snappy.compress(bytes);
  } catch (IOException e) {
    throw Throwables.throwUncheckedException(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 compressedSize = Snappy.compress(baOut.getBuffer(), 0, baOut.size(), compressed, 0);

代码示例来源:origin: org.apache.carbondata/carbondata-core

@Override public byte[] compressInt(int[] unCompInput) {
 try {
  return Snappy.compress(unCompInput);
 } catch (IOException e) {
  LOGGER.error(e.getMessage(), e);
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: jsevellec/cassandra-unit

public void compress(ByteBuffer input, ByteBuffer output) throws IOException
{
  int dlimit = output.limit();
  Snappy.compress(input, output);
  // Snappy doesn't match the ICompressor contract w/regards to state it leaves dest ByteBuffer's counters in
  output.position(output.limit());
  output.limit(dlimit);
  input.position(input.limit());
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public void compress(ByteBuffer input, ByteBuffer output) throws IOException
{
  int dlimit = output.limit();
  Snappy.compress(input, output);
  // Snappy doesn't match the ICompressor contract w/regards to state it leaves dest ByteBuffer's counters in
  output.position(output.limit());
  output.limit(dlimit);
  input.position(input.limit());
}

相关文章