Java Code Examples for org.xerial.snappy.Snappy#uncompress()

The following examples show how to use org.xerial.snappy.Snappy#uncompress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Compresss.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * Using snappy uncompress.
 * 
 * @param data
 * @return
 */
public static byte[] snappyUnCompress(byte[] data) {
	try {
		return Snappy.uncompress(data);
	} catch (IOException e) {
		throw new IllegalStateException(e);
	}
}
 
Example 2
Source File: StorageSerialization.java    From PalDB with Apache License 2.0 5 votes vote down vote up
private static byte[] deserializeByteCompressedArray(DataInput is)
    throws IOException {
  int size = LongPacker.unpackInt(is);
  byte[] b = new byte[size];
  is.readFully(b);
  return Snappy.uncompress(b);
}
 
Example 3
Source File: SnappyCompressor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] decompress(byte[] input) {
  try {
    return Snappy.uncompress(input);
  } catch (IOException e) {
    throw new CompressionException(e);
  }
}
 
Example 4
Source File: CompressionCodecSnappyJNI.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf decode(ByteBuf encoded, int uncompressedLength) throws IOException {
    ByteBuf uncompressed = PooledByteBufAllocator.DEFAULT.buffer(uncompressedLength, uncompressedLength);
    ByteBuffer uncompressedNio = uncompressed.nioBuffer(0, uncompressedLength);

    ByteBuffer encodedNio = encoded.nioBuffer(encoded.readerIndex(), encoded.readableBytes());
    Snappy.uncompress(encodedNio, uncompressedNio);

    uncompressed.writerIndex(uncompressedLength);
    return uncompressed;
}
 
Example 5
Source File: ValueSocketIterator.java    From count-db with MIT License 5 votes vote down vote up
private synchronized void findNextValues() {
    if (!wasClosed()) {
        try {
            long numOfValues = connection.readLong();
            if (numOfValues == LONG_END) {
                nextValues = null;
                readAllValuesFromConnection = true;
            } else if (numOfValues != LONG_ERROR) {
                byte[] compressedValues = connection.readByteArray();
                byte[] uncompressedValues = Snappy.uncompress(compressedValues);
                DataStream valueIS = new DataStream(uncompressedValues);
                List<T> nextValuesList = new ArrayList<>();
                while (nextValuesList.size() < numOfValues) {
                    int objectSize = DataStreamUtils.getObjectSize(valueIS, objectSerializer);
                    T value = objectSerializer.readValue(valueIS, objectSize);
                    nextValuesList.add(value);
                }
                if (nextValuesList.isEmpty()) {
                    throw new RuntimeException("Received zero values! numOfValues=" + numOfValues);
                }
                nextValues = nextValuesList.iterator();
            } else {
                throw new RuntimeException("Unexpected response " + connection.readString());

            }
        } catch (Exception e) {
            remoteDataInterface.dropConnection(connection);
            throw new RuntimeException(e);
        }
    } else {
        nextValues = null;
    }
}
 
Example 6
Source File: SnappyCompressor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] decompress(byte[] input) {
  try {
    return Snappy.uncompress(input);
  } catch (IOException e) {
    throw new CompressionException(e);
  }
}
 
Example 7
Source File: HashCacheFactory.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: SnappyRandomReader.java    From sparkey-java with Apache License 2.0 5 votes vote down vote up
private void fetchBlock() throws IOException {
  int compressedSize = Util.readUnsignedVLQInt(data);
  data.readFully(compressedBuf, 0, compressedSize);
  bufPos = 0;
  blockSize = Snappy.uncompress(compressedBuf, 0, compressedSize, uncompressedBuf, 0);
  position = -1;
}
 
Example 9
Source File: KeyValueSocketIterator.java    From count-db with MIT License 5 votes vote down vote up
private synchronized void findNextValues() {
    if (!wasClosed()) {
        try {
            long numOfValues = connection.readLong();
            if (numOfValues == LONG_END) {
                nextValues = null;
                readAllValuesFromConnection = true;
            } else if (numOfValues != LONG_ERROR) {
                byte[] keys = connection.readByteArray();
                byte[] compressedValues = connection.readByteArray();
                byte[] uncompressedValues = Snappy.uncompress(compressedValues);
                DataStream keyIS = new DataStream(keys);
                DataStream valueIS = new DataStream(uncompressedValues);
                List<KeyValue<T>> nextValuesList = new ArrayList<>();
                while (nextValuesList.size() < numOfValues) {
                    long key = keyIS.readLong();
                    int objectSize = DataStreamUtils.getObjectSize(valueIS, objectSerializer);
                    T value = objectSerializer.readValue(valueIS, objectSize);
                    nextValuesList.add(new KeyValue<>(key, value));
                }
                if (nextValuesList.isEmpty()) {
                    throw new RuntimeException("Received zero values! numOfValues=" + numOfValues);
                }
                nextValues = nextValuesList.iterator();
            } else {
                throw new RuntimeException("Unexpected response " + connection.readString());

            }
        } catch (Exception e) {
            remoteDataInterface.dropConnection(connection);
            throw new RuntimeException(e);
        }
    } else {
        nextValues = null;
    }
}
 
Example 10
Source File: SnappyCompressor.java    From besu with Apache License 2.0 5 votes vote down vote up
public byte[] decompress(final byte[] compressed) {
  checkNotNull(compressed, "input data must not be null");
  try {
    return Snappy.uncompress(compressed);
  } catch (final IOException e) {
    throw new FramingException("Snappy decompression failed", e);
  }
}
 
Example 11
Source File: FrameCompressor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: SnappyTest.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
@Test
public void testBytes() throws IOException {
  String input = randomString(50000);
  byte[] uncom = input.getBytes(StandardCharsets.UTF_8);
  long time = System.currentTimeMillis();
  byte[] compressed = Snappy.compress(uncom);
  System.out.println("compression time cost:" + (System.currentTimeMillis() - time));
  time = System.currentTimeMillis();
  byte[] uncompressed = Snappy.uncompress(compressed);
  System.out.println("decompression time cost:" + (System.currentTimeMillis() - time));
}
 
Example 13
Source File: SnappyCodecV2.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    byte[] bytes = new byte[buf.readableBytes()];
    buf.readBytes(bytes);
    bytes = Snappy.uncompress(bytes);
    ByteBuf bf = Unpooled.wrappedBuffer(bytes);
    try {
        return innerCodec.getValueDecoder().decode(bf, state);
    } finally {
        bf.release();
    }
}
 
Example 14
Source File: IUnCompressor.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] uncompress(byte[] bytes) {
  if (bytes == null) {
    return new byte[0];
  }

  try {
    return Snappy.uncompress(bytes);
  } catch (IOException e) {
    logger.error(
        "tsfile-compression SnappyUnCompressor: errors occurs when uncompress input byte", e);
  }
  return new byte[0];
}
 
Example 15
Source File: CompressUtil.java    From octo-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * Snappy解压
 * @param data
 * @return
 * @throws IOException
 */
public static byte[] uncompressSnappy(byte[] data) throws IOException {
    if (data == null) {
        return new byte[0];
    }
    return Snappy.uncompress(data);
}
 
Example 16
Source File: JBossMarshaller.java    From khan-session with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object objectFromByteBuffer(byte[] buf) throws IOException {
    byte[] uncompressBuf;
    ByteArrayInputStream bais = null;
    Object o = null;

    if( DEBUG )
        log.debug(StackTraceUtil.getStackTrace(Thread.currentThread().getStackTrace()) );

    try {
        if (USE_SNAPPY_COMPRESSION) {
            uncompressBuf = Snappy.uncompress(buf);
            if (DEBUG) {
                log.debug("KhanFSTMarshaller/toObject/SIZE=" + buf.length + "/UNCOMPRESS=" + uncompressBuf.length);
            }

            return MarshallerUtil.bytes2obj(marshaller, uncompressBuf);
        } else {
            if (DEBUG) {
                log.debug("KhanFSTMarshaller/toObject/SIZE=" + buf.length);
            }
            return MarshallerUtil.bytes2obj(marshaller, buf);
        }


    } catch (Exception e) {
        throw new IOException("Exception");
    }
}
 
Example 17
Source File: SnappyHelper.java    From litchi with Apache License 2.0 5 votes vote down vote up
/**
 * 解压
 * @param bytes
 * @return
 */
public static byte[] uncompress(byte[] bytes) {
	try {
		return Snappy.uncompress(bytes);
	} catch (Exception e) {
		LOGGER.warn("{}", e);
	}
	return null;
}
 
Example 18
Source File: DirectCodecFactory.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void decompress(ByteBuffer src, int compressedSize, ByteBuffer dst, int uncompressedSize) throws IOException {
  dst.clear();
  int size = Snappy.uncompress(src, dst);
  dst.limit(size);
}
 
Example 19
Source File: SnappyDecompressor.java    From Krackle with Apache License 2.0 4 votes vote down vote up
@Override
public int decompress(byte[] src, int srcPos, int length, byte[] dest,
	 int destPos, int maxLength) throws IOException {
	this.src = src;
	decompressedLength = 0;

	// Check for magic number
	if (src[srcPos] == MAGIC_NUMBER[0] //
		 || src[srcPos + 1] == MAGIC_NUMBER[1] //
		 || src[srcPos + 2] == MAGIC_NUMBER[2] //
		 || src[srcPos + 3] == MAGIC_NUMBER[3] //
		 || src[srcPos + 4] == MAGIC_NUMBER[4] //
		 || src[srcPos + 5] == MAGIC_NUMBER[5] //
		 || src[srcPos + 6] == MAGIC_NUMBER[6] //
		 || src[srcPos + 7] == MAGIC_NUMBER[7]) {

     // advance past the magic number
		// assume the version (4 bytes), min compatable version (4 bytes) are fine
		pos = srcPos + 8 + 8;

		// TODO: limit the decompressed length
		while (pos < srcPos + length) {
			blockLength = readInt();

			// Check to see if this will exceed maxLength
			uncompressedBlockLength = Snappy.uncompressedLength(src, pos,
				 blockLength);
			if (decompressedLength + uncompressedBlockLength > maxLength) {
				return -1;
			}

			decompressedLength += Snappy.uncompress(src, pos, blockLength, dest,
				 destPos + decompressedLength);
			pos += blockLength;
		}

		return decompressedLength;
	} else {
		// Assume it's just straight compressed
		return Snappy.uncompress(src, pos, blockLength, dest, destPos);
	}
}
 
Example 20
Source File: SnappyDecompressor.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public int decompress(ByteBuffer compressedInput, ByteBuffer decompressedOutput)
    throws IOException {
  return Snappy.uncompress(compressedInput, decompressedOutput);
}