Don't trigger IOException at ChunkedStream.isEndOfInput()

Related: #3368

Motivation:

ChunkedWriteHandler checks if the return value of
ChunkedInput.isEndOfInput() after calling ChunkedInput.close().

This makes ChunkedStream.isEndOfInput() trigger an IOException, which is
originally triggered by PushBackInputStream.read().

By contract, ChunkedInput.isEndOfInput() should not raise an IOException
even when the underlying stream is closed.

Modifications:

Add a boolean flag that keeps track of whether the underlying stream has
been closed or not, so that ChunkedStream.isEndOfInput() does not
propagate the IOException from PushBackInputStream.

Result:

Fixes #3368
This commit is contained in:
Trustin Lee 2015-03-31 11:31:54 +09:00
parent 0c6ba4aab6
commit 28caa873b3

View File

@ -38,6 +38,7 @@ public class ChunkedStream implements ChunkedInput<ByteBuf> {
private final PushbackInputStream in;
private final int chunkSize;
private long offset;
private boolean closed;
/**
* Creates a new instance that fetches data from the specified stream.
@ -79,6 +80,10 @@ public class ChunkedStream implements ChunkedInput<ByteBuf> {
@Override
public boolean isEndOfInput() throws Exception {
if (closed) {
return true;
}
int b = in.read();
if (b < 0) {
return true;
@ -90,6 +95,7 @@ public class ChunkedStream implements ChunkedInput<ByteBuf> {
@Override
public void close() throws Exception {
closed = true;
in.close();
}