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();
}
}
use of io.netty.handler.codec.EncoderException in project CodeChickenLib by Chicken-Bones.
the class PacketCustom method do_compress.
/**
* Compresses the payload ByteBuf after the type byte
*/
private void do_compress() {
Deflater deflater = new Deflater();
try {
readerIndex(1);
int len = readableBytes();
deflater.setInput(array(), readerIndex(), len);
deflater.finish();
byte[] out = new byte[len];
int clen = deflater.deflate(out);
if (// not worth compressing, gets larger
clen >= len - 5 || !deflater.finished())
return;
clear();
writeByte(type | 0x80);
writeVarInt(len);
writeByteArray(out);
} catch (Exception e) {
throw new EncoderException(e);
} finally {
readerIndex(0);
deflater.end();
}
}
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);
}
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
}
}
use of io.netty.handler.codec.EncoderException in project netty by netty.
the class HttpContentCompressorTest method testTooManyResponses.
@Test
public void testTooManyResponses() throws Exception {
FullHttpRequest request = newRequest();
EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor());
ch.writeInbound(request);
ch.writeOutbound(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER));
try {
ch.writeOutbound(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER));
fail();
} catch (EncoderException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}
assertTrue(ch.finish());
for (; ; ) {
Object message = ch.readOutbound();
if (message == null) {
break;
}
ReferenceCountUtil.release(message);
}
for (; ; ) {
Object message = ch.readInbound();
if (message == null) {
break;
}
ReferenceCountUtil.release(message);
}
}
Aggregations