本文整理了Java中org.xerial.snappy.Snappy.isValidCompressedBuffer()
方法的一些代码示例,展示了Snappy.isValidCompressedBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snappy.isValidCompressedBuffer()
方法的具体详情如下:
包路径:org.xerial.snappy.Snappy
类名称:Snappy
方法名:isValidCompressedBuffer
[英]Returns true iff the contents of compressed buffer [offset, offset+length) can be uncompressed successfully. Does not return the uncompressed data. Takes time proportional to the input length, but is usually at least a factor of four faster than actual decompression.
[中]如果压缩缓冲区[offset,offset+length]的内容可以成功解压缩,则返回true。不返回未压缩的数据。所需时间与输入长度成比例,但通常比实际解压缩速度至少快四倍。
代码示例来源:origin: redisson/redisson
/**
* Returns true iff the contents of compressed buffer [offset,
* offset+length) can be uncompressed successfully. Does not return the
* uncompressed data. Takes time proportional to the input length, but is
* usually at least a factor of four faster than actual decompression.
*/
public static boolean isValidCompressedBuffer(byte[] input)
throws IOException
{
return isValidCompressedBuffer(input, 0, input.length);
}
代码示例来源: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: 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: com.datastax.cassandra/cassandra-driver-core
if (!Snappy.isValidCompressedBuffer(in, inOffset, len))
throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
代码示例来源: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: com.palantir.atlasdb/atlasdb-client
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: snazy/ohc
if (!Snappy.isValidCompressedBuffer(compressedBuffer))
throw new IOException("Invalid compressed data");
r = Snappy.uncompress(compressedBuffer, decompressedBuffer);
代码示例来源:origin: org.scray/scray-client-jdbc
private Object decode(ByteBuffer bytes) throws SQLException {
Object obj = null;
try {
byte[] bytesArr = new byte[bytes.remaining()];
bytes.get(bytesArr);
byte[] rawSer = bytesArr;
if (bytesArr.length >= minCompressionSize) {
rawSer = Snappy.uncompress(bytesArr);
} else if (Snappy.isValidCompressedBuffer(bytesArr)) {
rawSer = Snappy.uncompress(bytesArr);
}
obj = KryoJavaPoolSerialization.getInstance().chill
.fromBytes(rawSer);
} catch (Exception ex) {
throw new SQLException("Serialization error.", ex);
}
return obj;
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
private ByteBuf decompressHeap(ByteBuf input) throws IOException {
// Not a direct buffer so use byte arrays...
int inOffset = input.arrayOffset() + input.readerIndex();
byte[] in = input.array();
int len = input.readableBytes();
// Increase reader index.
input.readerIndex(input.writerIndex());
if (!Snappy.isValidCompressedBuffer(in, inOffset, len))
throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
// 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(Snappy.uncompressedLength(in, inOffset, len));
try {
// Calculate the correct offset.
int offset = output.arrayOffset() + output.writerIndex();
byte[] out = output.array();
int written = Snappy.uncompress(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: io.prestosql.cassandra/cassandra-driver
private ByteBuf decompressHeap(ByteBuf input) throws IOException {
// Not a direct buffer so use byte arrays...
int inOffset = input.arrayOffset() + input.readerIndex();
byte[] in = input.array();
int len = input.readableBytes();
// Increase reader index.
input.readerIndex(input.writerIndex());
if (!Snappy.isValidCompressedBuffer(in, inOffset, len))
throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
// 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(Snappy.uncompressedLength(in, inOffset, len));
try {
// Calculate the correct offset.
int offset = output.arrayOffset() + output.writerIndex();
byte[] out = output.array();
int written = Snappy.uncompress(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.yugabyte/cassandra-driver-core
private ByteBuf decompressHeap(ByteBuf input) throws IOException {
// Not a direct buffer so use byte arrays...
int inOffset = input.arrayOffset() + input.readerIndex();
byte[] in = input.array();
int len = input.readableBytes();
// Increase reader index.
input.readerIndex(input.writerIndex());
if (!Snappy.isValidCompressedBuffer(in, inOffset, len))
throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
// 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(Snappy.uncompressedLength(in, inOffset, len));
try {
// Calculate the correct offset.
int offset = output.arrayOffset() + output.writerIndex();
byte[] out = output.array();
int written = Snappy.uncompress(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.facebook.presto.cassandra/cassandra-driver
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: io.prestosql.cassandra/cassandra-driver
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: com.yugabyte/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: com.strapdata.cassandra/cassandra-all
public Frame decompress(Frame frame) throws IOException
{
byte[] input = CBUtil.readRawBytes(frame.body);
if (!Snappy.isValidCompressedBuffer(input, 0, input.length))
throw new ProtocolException("Provided frame does not appear to be Snappy compressed");
ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.uncompressedLength(input));
try
{
int size = Snappy.uncompress(input, 0, input.length, output.array(), output.arrayOffset());
output.writerIndex(size);
}
catch (final Throwable e)
{
output.release();
throw e;
}
finally
{
//release the old frame
frame.release();
}
return frame.with(output);
}
}
代码示例来源:origin: org.apache.cassandra/cassandra-all
public Frame decompress(Frame frame) throws IOException
{
byte[] input = CBUtil.readRawBytes(frame.body);
if (!Snappy.isValidCompressedBuffer(input, 0, input.length))
throw new ProtocolException("Provided frame does not appear to be Snappy compressed");
ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.uncompressedLength(input));
try
{
int size = Snappy.uncompress(input, 0, input.length, output.array(), output.arrayOffset());
output.writerIndex(size);
}
catch (final Throwable e)
{
output.release();
throw e;
}
finally
{
//release the old frame
frame.release();
}
return frame.with(output);
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server
public Frame decompress(Frame frame) throws IOException
{
byte[] input = CBUtil.readRawBytes(frame.body);
if (!Snappy.isValidCompressedBuffer(input, 0, input.length))
throw new ProtocolException("Provided frame does not appear to be Snappy compressed");
ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.uncompressedLength(input));
try
{
int size = Snappy.uncompress(input, 0, input.length, output.array(), output.arrayOffset());
output.writerIndex(size);
}
catch (final Throwable e)
{
output.release();
throw e;
}
finally
{
//release the old frame
frame.release();
}
return frame.with(output);
}
}
代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core
public Frame decompress(Frame frame) throws IOException {
byte[] input = CBUtil.readRawBytes(frame.body);
if (!Snappy.isValidCompressedBuffer(input, 0, input.length))
throw new DriverInternalError("Provided frame does not appear to be Snappy compressed");
byte[] output = new byte[Snappy.uncompressedLength(input)];
int size = Snappy.uncompress(input, 0, input.length, output, 0);
return frame.with(ChannelBuffers.wrappedBuffer(output, 0, size));
}
}
代码示例来源:origin: com.datastax.oss/java-driver-core-shaded
@Override
protected ByteBuf decompressDirect(ByteBuf input) {
ByteBuffer in = inputNioBuffer(input);
// Increase reader index.
input.readerIndex(input.writerIndex());
ByteBuf output = null;
try {
if (!Snappy.isValidCompressedBuffer(in)) {
throw new IllegalArgumentException(
"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.
output = input.alloc().directBuffer(Snappy.uncompressedLength(in));
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);
return output;
} catch (IOException e) {
// release output buffer so we not leak and rethrow exception.
if (output != null) {
output.release();
}
throw new RuntimeException(e);
}
}
代码示例来源:origin: jsevellec/cassandra-unit
public Frame decompress(Frame frame) throws IOException
{
byte[] input = CBUtil.readRawBytes(frame.body);
if (!Snappy.isValidCompressedBuffer(input, 0, input.length))
throw new ProtocolException("Provided frame does not appear to be Snappy compressed");
ByteBuf output = CBUtil.allocator.heapBuffer(Snappy.uncompressedLength(input));
try
{
int size = Snappy.uncompress(input, 0, input.length, output.array(), output.arrayOffset());
output.writerIndex(size);
}
catch (final Throwable e)
{
output.release();
throw e;
}
finally
{
//release the old frame
frame.release();
}
return frame.with(output);
}
}
内容来源于网络,如有侵权,请联系作者删除!