Fixed issue: NETTY-67 (ChannelBuffer.writeBytes() and setBytes() should not throw ClosedChannelException)

This commit is contained in:
Trustin Lee 2008-11-16 13:52:47 +00:00
parent 9aec8119cb
commit 630473bf84
2 changed files with 14 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.GatheringByteChannel; import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel; import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@ -253,7 +254,12 @@ public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer {
int readBytes = 0; int readBytes = 0;
while (readBytes < length) { while (readBytes < length) {
int localReadBytes = in.read(slice); int localReadBytes;
try {
localReadBytes = in.read(slice);
} catch (ClosedChannelException e) {
localReadBytes = -1;
}
if (localReadBytes < 0) { if (localReadBytes < 0) {
if (readBytes == 0) { if (readBytes == 0) {
return -1; return -1;

View File

@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.GatheringByteChannel; import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel; import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@ -157,7 +158,12 @@ public abstract class HeapChannelBuffer extends AbstractChannelBuffer {
int readBytes = 0; int readBytes = 0;
do { do {
int localReadBytes = in.read(buf); int localReadBytes;
try {
localReadBytes = in.read(buf);
} catch (ClosedChannelException e) {
localReadBytes = -1;
}
if (localReadBytes < 0) { if (localReadBytes < 0) {
if (readBytes == 0) { if (readBytes == 0) {
return -1; return -1;