Search in sources :

Example 1 with ByteInput

use of org.jboss.marshalling.ByteInput in project netty by netty.

the class CompatibleMarshallingDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    if (discardingTooLongFrame) {
        buffer.skipBytes(actualReadableBytes());
        checkpoint();
        return;
    }
    Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
    ByteInput input = new ChannelBufferByteInput(buffer);
    if (maxObjectSize != Integer.MAX_VALUE) {
        input = new LimitingByteInput(input, maxObjectSize);
    }
    try {
        unmarshaller.start(input);
        Object obj = unmarshaller.readObject();
        unmarshaller.finish();
        out.add(obj);
    } catch (LimitingByteInput.TooBigObjectException ignored) {
        discardingTooLongFrame = true;
        throw new TooLongFrameException();
    } finally {
        // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
        // readable. This helps to be sure that we do not leak resource
        unmarshaller.close();
    }
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) ByteInput(org.jboss.marshalling.ByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 2 with ByteInput

use of org.jboss.marshalling.ByteInput in project netty by netty.

the class MarshallingDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }
    Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
    ByteInput input = new ChannelBufferByteInput(frame);
    try {
        unmarshaller.start(input);
        Object obj = unmarshaller.readObject();
        unmarshaller.finish();
        return obj;
    } finally {
        // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
        // readable. This helps to be sure that we do not leak resource
        unmarshaller.close();
    }
}
Also used : ByteInput(org.jboss.marshalling.ByteInput) ByteBuf(io.netty.buffer.ByteBuf) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Aggregations

ByteInput (org.jboss.marshalling.ByteInput)2 Unmarshaller (org.jboss.marshalling.Unmarshaller)2 ByteBuf (io.netty.buffer.ByteBuf)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1