Search in sources :

Example 16 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project weave by continuuity.

the class AbstractCompressedMessageSetEncoder method finish.

@Override
public final ChannelBuffer finish() {
    try {
        compressedOutput.close();
        ChannelBuffer buf = prefixLength(encodePayload(os.buffer(), compression));
        compressedOutput = createCompressedStream(os);
        os.buffer().clear();
        return buf;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 17 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project weave by continuuity.

the class AbstractCompressedMessageSetEncoder method add.

@Override
public final MessageSetEncoder add(ChannelBuffer payload) {
    try {
        ChannelBuffer encoded = encodePayload(payload);
        encoded.readBytes(compressedOutput, encoded.readableBytes());
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return this;
}
Also used : IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 18 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project weave by continuuity.

the class AbstractMessageSetEncoder method prefixLength.

protected final ChannelBuffer prefixLength(ChannelBuffer buffer) {
    ChannelBuffer sizeBuf = ChannelBuffers.buffer(4);
    sizeBuf.writeInt(buffer.readableBytes());
    return ChannelBuffers.wrappedBuffer(sizeBuf, buffer);
}
Also used : ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 19 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project weave by continuuity.

the class AbstractMessageSetEncoder method encodePayload.

protected final ChannelBuffer encodePayload(ChannelBuffer payload, Compression compression) {
    ChannelBuffer header = ChannelBuffers.buffer(10);
    int crc = computeCRC32(payload);
    int magic = ((compression == Compression.NONE) ? 0 : 1);
    // Message length = 1 byte magic + (optional 1 compression byte) + 4 bytes crc + payload length
    header.writeInt(5 + magic + payload.readableBytes());
    // Magic number = 0 for non-compressed data
    header.writeByte(magic);
    if (magic > 0) {
        header.writeByte(compression.getCode());
    }
    header.writeInt(crc);
    return ChannelBuffers.wrappedBuffer(header, payload);
}
Also used : ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 20 with ChannelBuffer

use of org.jboss.netty.buffer.ChannelBuffer in project weave by continuuity.

the class Bufferer method getNext.

/**
   * Returns the buffer if the buffer data is ready to be consumed,
   * otherwise return {@link ChannelBuffers#EMPTY_BUFFER}.
   */
ChannelBuffer getNext() {
    if (currentSize < 0) {
        if (currentBuffer.readableBytes() < 4) {
            return ChannelBuffers.EMPTY_BUFFER;
        }
        currentSize = currentBuffer.readInt();
    }
    // Keep buffering if less then required number of bytes
    if (currentBuffer.readableBytes() < currentSize) {
        return ChannelBuffers.EMPTY_BUFFER;
    }
    ChannelBuffer result = currentBuffer.readSlice(currentSize);
    currentSize = -1;
    return result;
}
Also used : ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)312 Test (org.junit.Test)63 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)59 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)49 Test (org.testng.annotations.Test)49 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)46 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)43 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)37 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)34 Checkpoint (com.linkedin.databus.core.Checkpoint)27 ByteBuffer (java.nio.ByteBuffer)27 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 IOException (java.io.IOException)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 ArrayList (java.util.ArrayList)21 Channel (org.jboss.netty.channel.Channel)19 ChannelFuture (org.jboss.netty.channel.ChannelFuture)18 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)17 BlockLogBuffer (org.neo4j.com.BlockLogBuffer)16 Map (java.util.Map)14