Search in sources :

Example 6 with EncoderException

use of io.netty.handler.codec.EncoderException in project CodeChickenLib by Chicken-Bones.

the class PacketCustom method decompress.

/**
     * Decompresses the remaining ByteBuf (after type has been read) using Snappy
     */
private void decompress() {
    Inflater inflater = new Inflater();
    try {
        int len = readInt();
        byte[] out = new byte[len];
        inflater.setInput(array(), readerIndex(), readableBytes());
        inflater.inflate(out);
        clear();
        writeByteArray(out);
    } catch (Exception e) {
        throw new EncoderException(e);
    } finally {
        inflater.end();
    }
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) Inflater(java.util.zip.Inflater) EncoderException(io.netty.handler.codec.EncoderException) IOException(java.io.IOException)

Example 7 with EncoderException

use of io.netty.handler.codec.EncoderException in project CodeChickenLib by Chicken-Bones.

the class MCDataIO method writeString.

/**
     * PacketBuffer.writeString
     */
public static void writeString(MCDataOutput out, String string) {
    byte[] abyte = string.getBytes(Charsets.UTF_8);
    if (abyte.length > 32767)
        throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + 32767 + ")");
    out.writeVarInt(abyte.length);
    out.writeArray(abyte);
}
Also used : EncoderException(io.netty.handler.codec.EncoderException)

Example 8 with EncoderException

use of io.netty.handler.codec.EncoderException in project netty by netty.

the class LengthFieldPrependerTest method testAdjustedLengthLessThanZero.

@Test
public void testAdjustedLengthLessThanZero() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -2));
    try {
        ch.writeOutbound(msg);
        fail(EncoderException.class.getSimpleName() + " must be raised.");
    } catch (EncoderException e) {
    // Expected
    }
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) Test(org.junit.Test)

Aggregations

EncoderException (io.netty.handler.codec.EncoderException)8 IOException (java.io.IOException)3 ByteBuf (io.netty.buffer.ByteBuf)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Test (org.junit.Test)2 CodecRegistration (com.flowpowered.network.Codec.CodecRegistration)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)1 Deflater (java.util.zip.Deflater)1 Inflater (java.util.zip.Inflater)1 Nullable (javax.annotation.Nullable)1 NBTSizeTracker (net.minecraft.nbt.NBTSizeTracker)1