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

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

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

Snappy.uncompress介绍

[英]Uncompress the content in the input buffer. The result is dumped to the specified output buffer.

Note that if you pass the wrong data or the range [pos(), limit()) that cannot be uncompressed, your JVM might crash due to the access violation exception issued in the native code written in C++. To avoid this type of crash, use #isValidCompressedBuffer(ByteBuffer) first.
[中]解压缩输入缓冲区中的内容。结果被转储到指定的输出缓冲区。
请注意,如果您传递的数据或范围(POST)、LIMIT()不被压缩,则JVM可能由于在C++中编写的本机代码中发布的访问异常而崩溃。为了避免这种类型的崩溃,首先使用ByteBuffer。

代码示例

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

/**
 * High-level API for uncompressing the input byte array.
 *
 * @param input
 * @return the uncompressed byte array
 * @throws IOException
 */
public static byte[] uncompress(byte[] input)
    throws IOException
{
  byte[] result = new byte[Snappy.uncompressedLength(input)];
  Snappy.uncompress(input, 0, input.length, result, 0);
  return result;
}

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

@Override
 public int decompress(ByteBuffer compressedInput, ByteBuffer decompressedOutput)
   throws IOException {
  return Snappy.uncompress(compressedInput, decompressedOutput);
 }
}

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

/**
 * Uncompress the input[offset, offset+length) as a String of the given
 * encoding
 *
 * @param input
 * @param offset
 * @param length
 * @param encoding
 * @return the uncompressed data
 * @throws IOException
 */
public static String uncompressString(byte[] input, int offset, int length, Charset encoding)
    throws IOException,
    UnsupportedEncodingException
{
  byte[] uncompressed = new byte[uncompressedLength(input, offset, length)];
  uncompress(input, offset, length, uncompressed, 0);
  return new String(uncompressed, encoding);
}

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

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

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

/**
 * Uncompress the input[offset, offset+length) as a String of the given
 * encoding
 *
 * @param input
 * @param offset
 * @param length
 * @param encoding
 * @return the uncompressed data
 * @throws IOException
 */
public static String uncompressString(byte[] input, int offset, int length, String encoding)
    throws IOException,
    UnsupportedEncodingException
{
  byte[] uncompressed = new byte[uncompressedLength(input, offset, length)];
  uncompress(input, offset, length, uncompressed, 0);
  return new String(uncompressed, encoding);
}

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

/**
 * Uncompress the input as a String of the given encoding
 *
 * @param input
 * @param encoding
 * @return the uncompressed data
 * @throws IOException
 * @throws UnsupportedEncodingException
 */
public static String uncompressString(byte[] input, String encoding)
    throws IOException,
    UnsupportedEncodingException
{
  byte[] uncompressed = uncompress(input);
  return new String(uncompressed, encoding);
}

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

protected void readFully(byte[] fragment, int fragmentLength)
    throws IOException
{
  if (fragmentLength == 0) {
    finishedReading = true;
    return;
  }
  // read the entire input data to the buffer
  compressed = new byte[Math.max(8 * 1024, fragmentLength)]; // 8K
  System.arraycopy(fragment, 0, compressed, 0, fragmentLength);
  int cursor = fragmentLength;
  for (int readBytes = 0; (readBytes = in.read(compressed, cursor, compressed.length - cursor)) != -1; ) {
    cursor += readBytes;
    if (cursor >= compressed.length) {
      byte[] newBuf = new byte[(compressed.length * 2)];
      System.arraycopy(compressed, 0, newBuf, 0, compressed.length);
      compressed = newBuf;
    }
  }
  finishedReading = true;
  // Uncompress
  int uncompressedLength = Snappy.uncompressedLength(compressed, 0, cursor);
  uncompressed = new byte[uncompressedLength];
  Snappy.uncompress(compressed, 0, cursor, uncompressed, 0);
  this.uncompressedCursor = 0;
  this.uncompressedLimit = uncompressedLength;
}

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

/**
   * Uncompress the input as a String of the given encoding
   *
   * @param input
   * @param encoding
   * @return the uncompressed data
   * @throws IOException
   */
  public static String uncompressString(byte[] input, Charset encoding)
      throws IOException,
      UnsupportedEncodingException
  {
    byte[] uncompressed = uncompress(input);
    return new String(uncompressed, encoding);
  }
}

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

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

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

Snappy.uncompress(page, dst);

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

@Override
public ByteBuffer decompress(ByteBuffer in) throws IOException {
 ByteBuffer out = ByteBuffer.allocate
  (Snappy.uncompressedLength(in.array(),in.position(),in.remaining()-4));
 int size = Snappy.uncompress(in.array(),in.position(),in.remaining()-4,
                out.array(), 0);
 out.limit(size);
 crc32.reset();
 crc32.update(out.array(), 0, size);
 if (in.getInt(in.limit()-4) != (int)crc32.getValue())
  throw new IOException("Checksum failure");
 return out;
}

代码示例来源:origin: palantir/atlasdb

public static byte[] decompressWithSnappy(byte[] bytes) {
    try {
      if (!Snappy.isValidCompressedBuffer(bytes)) {
        throw new IllegalArgumentException("Cannot decompress these bytes using Snappy");
      }
      return Snappy.uncompress(bytes);
    } catch (IOException e) {
      throw Throwables.throwUncheckedException(e);
    }
  }
}

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

@Override
public ByteBuffer decompress(ByteBuffer in) throws IOException {
 int offset = computeOffset(in);
 ByteBuffer out = ByteBuffer.allocate
  (Snappy.uncompressedLength(in.array(), offset, in.remaining()-4));
 int size = Snappy.uncompress(in.array(), offset, in.remaining()-4,
                out.array(), 0);
 out.limit(size);
 crc32.reset();
 crc32.update(out.array(), 0, size);
 if (in.getInt(in.limit()-4) != (int)crc32.getValue())
  throw new IOException("Checksum failure");
 return out;
}

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

public void uncompress(ByteBuffer input, ByteBuffer output)
    throws IOException
{
  int dlimit = output.limit();
  Snappy.uncompress(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: kairosdb/kairosdb

@Override
public DataPoint getDataPoint(long timestamp, KDataInput buffer) throws IOException
{
  int buffSz = buffer.readUnsignedShort();
  byte[] byteBuffer = new byte[buffSz];
  buffer.readFully(byteBuffer, 0, buffSz);
  String result;
  if (Snappy.isValidCompressedBuffer(byteBuffer, 0, buffSz))
  {
    byte[] uncompressedArray = new byte[Snappy.uncompressedLength(byteBuffer, 0, buffSz)];
    int incompressedLength = Snappy.uncompress(byteBuffer, 0, buffSz, uncompressedArray, 0);
    result = new String(uncompressedArray, 0, incompressedLength, UTF8);
  }
  else
  {
    result = new String(byteBuffer, UTF8);
  }
  SnappyStringDataPoint ret = new SnappyStringDataPoint(timestamp, result);
  return ret;
}

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

this.valid = Snappy.uncompress(input, uncompressedDirect);

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

uncompressed = new byte[uncompressedLength];
int actualUncompressedLength = Snappy.uncompress(compressed, 0, chunkSize, uncompressed, 0);
if (uncompressedLength != actualUncompressedLength) {
  throw new SnappyIOException(SnappyErrorCode.INVALID_CHUNK_SIZE, String.format("expected %,d bytes, but decompressed chunk has %,d bytes", uncompressedLength, actualUncompressedLength));

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

@Override
public Closeable newCache(ImmutableBytesWritable cachePtr, MemoryChunk chunk) throws SQLException {
  try {
    int size = Snappy.uncompressedLength(cachePtr.get());
    byte[] uncompressed = new byte[size];
    Snappy.uncompress(cachePtr.get(), 0, cachePtr.getLength(), uncompressed, 0);
    return new HashCacheImpl(uncompressed, chunk);
  } catch (IOException e) {
    throw ServerUtil.parseServerException(e);
  }
}

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

int written = Snappy.uncompress(in, inOffset, len, out, offset);

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

private ByteBuf decompressDirect(ByteBuf input) throws IOException {
 ByteBuffer in = inputNioBuffer(input);
 // Increase reader index.
 input.readerIndex(input.writerIndex());
 if (!Snappy.isValidCompressedBuffer(in))
  throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
 // 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(Snappy.uncompressedLength(in));
 try {
  ByteBuffer out = outputNioBuffer(output);
  int size = Snappy.uncompress(in, out);
  // Set the writer index so the amount of written bytes is reflected
  output.writerIndex(output.writerIndex() + size);
 } catch (IOException e) {
  // release output buffer so we not leak and rethrow exception.
  output.release();
  throw e;
 }
 return output;
}

相关文章