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

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

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

Snappy.uncompressedLength介绍

[英]Get the uncompressed byte size of the given compressed input. This operation takes O(1) time.
[中]获取给定压缩输入的未压缩字节大小。此操作需要0(1)个时间。

代码示例

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

/**
 * Uncompress the input as a double array
 *
 * @param input
 * @return the uncompressed data
 * @throws IOException
 */
public static double[] uncompressDoubleArray(byte[] input)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, 0, input.length);
  double[] result = new double[uncompressedLength / 8];
  impl.rawUncompress(input, 0, input.length, result, 0);
  return result;
}

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

/**
 * Uncompress the input[offset, .., offset+length) as a char array
 *
 * @param input
 * @param offset
 * @param length
 * @return the uncompressed data
 * @throws IOException
 */
public static char[] uncompressCharArray(byte[] input, int offset, int length)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, offset, length);
  char[] result = new char[uncompressedLength / 2];
  impl.rawUncompress(input, offset, length, result, 0);
  return result;
}

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

/**
 * Uncompress the input[offset, offset+length) as a short array
 *
 * @param input
 * @param offset
 * @param length
 * @return the uncompressed data
 * @throws IOException
 */
public static short[] uncompressShortArray(byte[] input, int offset, int length)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, offset, length);
  short[] result = new short[uncompressedLength / 2];
  impl.rawUncompress(input, offset, length, result, 0);
  return result;
}

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

/**
 * Uncompress the input[offset, offset+length) as a float array
 *
 * @param input
 * @param offset
 * @param length
 * @return the uncompressed data
 * @throws IOException
 */
public static float[] uncompressFloatArray(byte[] input, int offset, int length)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, offset, length);
  float[] result = new float[uncompressedLength / 4];
  impl.rawUncompress(input, offset, length, result, 0);
  return result;
}

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

/**
 * Uncompress the input[offset, offset+length) as an int array
 *
 * @param input
 * @param offset
 * @param length
 * @return the uncompressed data
 * @throws IOException
 */
public static int[] uncompressIntArray(byte[] input, int offset, int length)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, offset, length);
  int[] result = new int[uncompressedLength / 4];
  impl.rawUncompress(input, offset, length, result, 0);
  return result;
}

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

/**
 * Uncompress the input[offset, offset+length) as a long array
 *
 * @param input
 * @param offset
 * @param length
 * @return the uncompressed data
 * @throws IOException
 */
public static long[] uncompressLongArray(byte[] input, int offset, int length)
    throws IOException
{
  int uncompressedLength = Snappy.uncompressedLength(input, offset, length);
  long[] result = new long[uncompressedLength / 8];
  impl.rawUncompress(input, offset, length, result, 0);
  return result;
}

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

@Override
protected void decode(ChannelHandlerContext ctx, FrameCodec.Frame msg, List<Object> out) throws Exception {
  byte[] in = new byte[msg.size];
  msg.payload.read(in);
  long uncompressedLength = Snappy.uncompressedLength(in) & 0xFFFFFFFFL;
  if (uncompressedLength > MAX_SIZE) {
    logger.info("{}: uncompressed frame size exceeds the limit ({} bytes), drop the peer", channel, uncompressedLength);
    channel.disconnect(ReasonCode.BAD_PROTOCOL);
    return;
  }
  byte[] uncompressed = new byte[(int) uncompressedLength];
  try {
    Snappy.rawUncompress(in, 0, in.length, uncompressed, 0);
  } catch (IOException e) {
    String detailMessage = e.getMessage();
    // 5 - error code for framed snappy
    if (detailMessage.startsWith("FAILED_TO_UNCOMPRESS") && detailMessage.contains("5")) {
      logger.info("{}: Snappy frames are not allowed in DEVp2p protocol, drop the peer", channel);
      channel.disconnect(ReasonCode.BAD_PROTOCOL);
      return;
    } else {
      throw e;
    }
  }
  out.add(new FrameCodec.Frame((int) msg.type, uncompressed));
}

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

final int uncompressedLength = Snappy.uncompressedLength(input);

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

throw new IOException("failed to read chunk");
int uncompressedLength = Snappy.uncompressedLength(compressed, 0, chunkSize);
if (uncompressed == null || uncompressedLength > uncompressed.length) {
  uncompressed = new byte[uncompressedLength];

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

ByteBuf output = input.alloc().heapBuffer(Snappy.uncompressedLength(in, inOffset, len));
try {

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

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

相关文章