Search in sources :

Example 1 with LZ4FastDecompressor

use of net.jpountz.lz4.LZ4FastDecompressor in project druid by druid-io.

the class LZ4Transcoder method decompress.

@Override
protected byte[] decompress(byte[] in) {
    byte[] out = null;
    if (in != null) {
        LZ4FastDecompressor decompressor = lz4Factory.fastDecompressor();
        int size = ByteBuffer.wrap(in).getInt();
        out = new byte[size];
        decompressor.decompress(in, Ints.BYTES, out, 0, out.length);
    }
    return out == null ? null : out;
}
Also used : LZ4FastDecompressor(net.jpountz.lz4.LZ4FastDecompressor)

Example 2 with LZ4FastDecompressor

use of net.jpountz.lz4.LZ4FastDecompressor in project cassandra by apache.

the class IncomingTcpConnection method receiveMessages.

// Not closing constructed DataInputPlus's as the stream needs to remain open.
@SuppressWarnings("resource")
private void receiveMessages() throws IOException {
    // handshake (true) endpoint versions
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    // if this version is < the MS version the other node is trying
    // to connect with, the other node will disconnect
    out.writeInt(MessagingService.current_version);
    out.flush();
    DataInputPlus in = new DataInputStreamPlus(socket.getInputStream());
    int maxVersion = in.readInt();
    // outbound side will reconnect if necessary to upgrade version
    assert version <= MessagingService.current_version;
    from = CompactEndpointSerializationHelper.deserialize(in);
    // record the (true) version of the endpoint
    MessagingService.instance().setVersion(from, maxVersion);
    logger.trace("Set version for {} to {} (will use {})", from, maxVersion, MessagingService.instance().getVersion(from));
    if (compressed) {
        logger.trace("Upgrading incoming connection to be compressed");
        LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
        Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(OutboundTcpConnection.LZ4_HASH_SEED).asChecksum();
        in = new DataInputStreamPlus(new LZ4BlockInputStream(socket.getInputStream(), decompressor, checksum));
    } else {
        ReadableByteChannel channel = socket.getChannel();
        in = new NIODataInputStream(channel != null ? channel : Channels.newChannel(socket.getInputStream()), BUFFER_SIZE);
    }
    while (true) {
        MessagingService.validateMagic(in.readInt());
        receiveMessage(in, version);
    }
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) LZ4FastDecompressor(net.jpountz.lz4.LZ4FastDecompressor) Checksum(java.util.zip.Checksum) DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) NIODataInputStream(org.apache.cassandra.io.util.NIODataInputStream)

Example 3 with LZ4FastDecompressor

use of net.jpountz.lz4.LZ4FastDecompressor in project SilverKing by Morgan-Stanley.

the class LZ4 method decompress.

public byte[] decompress(byte[] value, int offset, int length, int uncompressedLength) throws IOException {
    LZ4FastDecompressor decompressor;
    byte[] restored;
    decompressor = factory.fastDecompressor();
    restored = new byte[uncompressedLength];
    decompressor.decompress(value, offset, restored, 0, uncompressedLength);
    return restored;
}
Also used : LZ4FastDecompressor(net.jpountz.lz4.LZ4FastDecompressor)

Example 4 with LZ4FastDecompressor

use of net.jpountz.lz4.LZ4FastDecompressor in project vespa by vespa-engine.

the class NormalSketch method onDeserialize.

@Override
protected void onDeserialize(Deserializer buf) {
    super.onDeserialize(buf);
    int length = buf.getInt(null);
    int compressedLength = buf.getInt(null);
    Preconditions.checkState(length == data.length, "Size of serialized sketch does not match expected value. Expected %s, actual %s.", data.length, length);
    if (length == compressedLength) {
        deserializeDataArray(data, length, buf);
    } else {
        LZ4FastDecompressor c = LZ4Factory.safeInstance().fastDecompressor();
        byte[] compressedData = buf.getBytes(null, compressedLength);
        c.decompress(compressedData, data);
    }
}
Also used : LZ4FastDecompressor(net.jpountz.lz4.LZ4FastDecompressor)

Example 5 with LZ4FastDecompressor

use of net.jpountz.lz4.LZ4FastDecompressor in project druid by druid-io.

the class LZ4Transcoder method decompress.

@Override
protected byte[] decompress(byte[] in) {
    byte[] out = null;
    if (in != null) {
        LZ4FastDecompressor decompressor = lz4Factory.fastDecompressor();
        int size = ByteBuffer.wrap(in).getInt();
        out = new byte[size];
        decompressor.decompress(in, Integer.BYTES, out, 0, out.length);
    }
    return out == null ? null : out;
}
Also used : LZ4FastDecompressor(net.jpountz.lz4.LZ4FastDecompressor)

Aggregations

LZ4FastDecompressor (net.jpountz.lz4.LZ4FastDecompressor)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 PacketClassPool (com.nhnent.eat.common.PacketClassPool)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 Checksum (java.util.zip.Checksum)1 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)1 LZ4Factory (net.jpountz.lz4.LZ4Factory)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 DataInputStreamPlus (org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus)1 NIODataInputStream (org.apache.cassandra.io.util.NIODataInputStream)1