Clean up try/catch blocks / Prefer 'throw' to 'fireExceptionCaught'
This commit is contained in:
parent
3b9994455a
commit
c03179c81c
|
@ -82,19 +82,16 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
|||
int oldOutSize = out.readableBytes();
|
||||
try {
|
||||
decodeLast(ctx, in, out);
|
||||
} catch (CodecException e) {
|
||||
throw e;
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof CodecException) {
|
||||
ctx.fireExceptionCaught(t);
|
||||
} else {
|
||||
ctx.fireExceptionCaught(new DecoderException(t));
|
||||
throw new DecoderException(t);
|
||||
} finally {
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
ctx.fireChannelInactive();
|
||||
}
|
||||
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
|
||||
ctx.fireChannelInactive();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,25 +99,23 @@ public abstract class ByteToByteDecoder extends ChannelInboundByteHandlerAdapter
|
|||
*/
|
||||
private void callDecode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) {
|
||||
int oldOutSize = out.readableBytes();
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
try {
|
||||
decode(ctx, in, out);
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof CodecException) {
|
||||
ctx.fireExceptionCaught(t);
|
||||
} else {
|
||||
ctx.fireExceptionCaught(new DecoderException(t));
|
||||
try {
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
decode(ctx, in, out);
|
||||
if (oldInSize == in.readableBytes() || isSingleDecode()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (oldInSize == in.readableBytes() || isSingleDecode()) {
|
||||
break;
|
||||
} catch (CodecException e) {
|
||||
throw e;
|
||||
} catch (Throwable t) {
|
||||
throw new DecoderException(t);
|
||||
} finally {
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
if (out.readableBytes() > oldOutSize) {
|
||||
ctx.fireInboundBufferUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,28 +57,25 @@ public abstract class ByteToByteEncoder extends ChannelOutboundByteHandlerAdapte
|
|||
ByteBuf out = ctx.nextOutboundByteBuffer();
|
||||
boolean encoded = false;
|
||||
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
try {
|
||||
try {
|
||||
while (in.isReadable()) {
|
||||
int oldInSize = in.readableBytes();
|
||||
encode(ctx, in, out);
|
||||
encoded = true;
|
||||
} catch (Throwable t) {
|
||||
Throwable cause;
|
||||
if (t instanceof CodecException) {
|
||||
cause = t;
|
||||
} else {
|
||||
cause = new EncoderException(t);
|
||||
if (oldInSize == in.readableBytes()) {
|
||||
break;
|
||||
}
|
||||
if (encoded) {
|
||||
cause = new IncompleteFlushException("unable to encode all bytes", cause);
|
||||
}
|
||||
in.discardSomeReadBytes();
|
||||
promise.setFailure(cause);
|
||||
return;
|
||||
}
|
||||
if (oldInSize == in.readableBytes()) {
|
||||
break;
|
||||
} catch (Throwable t) {
|
||||
if (!(t instanceof CodecException)) {
|
||||
t = new EncoderException(t);
|
||||
}
|
||||
if (encoded) {
|
||||
t = new IncompleteFlushException("unable to encode all bytes", t);
|
||||
}
|
||||
in.discardSomeReadBytes();
|
||||
promise.setFailure(t);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.flush(promise);
|
||||
|
|
Loading…
Reference in New Issue
Block a user