Search in sources :

Example 6 with FastByteArrayOutputStream

use of org.apache.cassandra.io.util.FastByteArrayOutputStream in project eiger by wlloyd.

the class CassandraServer method uncompress.

private static String uncompress(ByteBuffer query, Compression compression) throws InvalidRequestException {
    String queryString = null;
    // Decompress the query string.
    try {
        switch(compression) {
            case GZIP:
                FastByteArrayOutputStream byteArray = new FastByteArrayOutputStream();
                byte[] outBuffer = new byte[1024], inBuffer = new byte[1024];
                Inflater decompressor = new Inflater();
                int lenRead = 0;
                while (true) {
                    if (decompressor.needsInput())
                        lenRead = query.remaining() < 1024 ? query.remaining() : 1024;
                    query.get(inBuffer, 0, lenRead);
                    decompressor.setInput(inBuffer, 0, lenRead);
                    int lenWrite = 0;
                    while ((lenWrite = decompressor.inflate(outBuffer)) != 0) byteArray.write(outBuffer, 0, lenWrite);
                    if (decompressor.finished())
                        break;
                }
                decompressor.end();
                queryString = new String(byteArray.toByteArray(), 0, byteArray.size(), "UTF-8");
                break;
            case NONE:
                try {
                    queryString = ByteBufferUtil.string(query);
                } catch (CharacterCodingException ex) {
                    throw new InvalidRequestException(ex.getMessage());
                }
                break;
        }
    } catch (DataFormatException e) {
        throw new InvalidRequestException("Error deflating query string.");
    } catch (UnsupportedEncodingException e) {
        throw new InvalidRequestException("Unknown query string encoding.");
    }
    return queryString;
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) DataFormatException(java.util.zip.DataFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inflater(java.util.zip.Inflater) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 7 with FastByteArrayOutputStream

use of org.apache.cassandra.io.util.FastByteArrayOutputStream in project eiger by wlloyd.

the class StreamReply method getMessage.

public Message getMessage(Integer version) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    serializer.serialize(this, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.STREAM_REPLY, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message)

Example 8 with FastByteArrayOutputStream

use of org.apache.cassandra.io.util.FastByteArrayOutputStream in project eiger by wlloyd.

the class Gossiper method makeGossipDigestAck2Message.

Message makeGossipDigestAck2Message(GossipDigestAck2Message gDigestAck2Message, int version) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    GossipDigestAck2Message.serializer().serialize(gDigestAck2Message, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.GOSSIP_DIGEST_ACK2, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message) DataOutputStream(java.io.DataOutputStream)

Example 9 with FastByteArrayOutputStream

use of org.apache.cassandra.io.util.FastByteArrayOutputStream in project eiger by wlloyd.

the class TruncateResponse method makeTruncateResponseMessage.

public static Message makeTruncateResponseMessage(Message original, TruncateResponse truncateResponseMessage) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    TruncateResponse.serializer().serialize(truncateResponseMessage, dos, original.getVersion());
    return original.getReply(FBUtilities.getBroadcastAddress(), bos.toByteArray(), original.getVersion());
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream)

Example 10 with FastByteArrayOutputStream

use of org.apache.cassandra.io.util.FastByteArrayOutputStream in project eiger by wlloyd.

the class TruncationSerializer method getMessage.

public Message getMessage(Integer version) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    serializer().serialize(this, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.TRUNCATE, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message)

Aggregations

FastByteArrayOutputStream (org.apache.cassandra.io.util.FastByteArrayOutputStream)10 Message (org.apache.cassandra.net.Message)7 DataOutputStream (java.io.DataOutputStream)4 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 DataFormatException (java.util.zip.DataFormatException)1 Inflater (java.util.zip.Inflater)1 Column (org.apache.cassandra.db.Column)1 IColumn (org.apache.cassandra.db.IColumn)1