diff --git a/src/main/java/org/jboss/netty/buffer/ByteBufferBackedChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/ByteBufferBackedChannelBuffer.java index 77ec270a19..73e9e2445e 100644 --- a/src/main/java/org/jboss/netty/buffer/ByteBufferBackedChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/ByteBufferBackedChannelBuffer.java @@ -28,6 +28,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.channels.ClosedChannelException; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; import java.nio.charset.UnsupportedCharsetException; @@ -253,7 +254,12 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer { int readBytes = 0; while (readBytes < length) { - int localReadBytes = in.read(slice); + int localReadBytes; + try { + localReadBytes = in.read(slice); + } catch (ClosedChannelException e) { + localReadBytes = -1; + } if (localReadBytes < 0) { if (readBytes == 0) { return -1; diff --git a/src/main/java/org/jboss/netty/buffer/HeapChannelBuffer.java b/src/main/java/org/jboss/netty/buffer/HeapChannelBuffer.java index 64b486562d..4ce8440ffc 100644 --- a/src/main/java/org/jboss/netty/buffer/HeapChannelBuffer.java +++ b/src/main/java/org/jboss/netty/buffer/HeapChannelBuffer.java @@ -27,6 +27,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; import java.nio.charset.UnsupportedCharsetException; @@ -157,7 +158,12 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer { int readBytes = 0; do { - int localReadBytes = in.read(buf); + int localReadBytes; + try { + localReadBytes = in.read(buf); + } catch (ClosedChannelException e) { + localReadBytes = -1; + } if (localReadBytes < 0) { if (readBytes == 0) { return -1;