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;
}
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);
}
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);
}
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());
}
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);
}
Aggregations