From 28caa873b3350053dfe6dfddbee48489dbe2c94a Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 31 Mar 2015 11:31:54 +0900 Subject: [PATCH] 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 --- .../main/java/io/netty/handler/stream/ChunkedStream.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/handler/src/main/java/io/netty/handler/stream/ChunkedStream.java b/handler/src/main/java/io/netty/handler/stream/ChunkedStream.java index e50d4fbc57..65bef1df4d 100644 --- a/handler/src/main/java/io/netty/handler/stream/ChunkedStream.java +++ b/handler/src/main/java/io/netty/handler/stream/ChunkedStream.java @@ -38,6 +38,7 @@ public class ChunkedStream implements ChunkedInput { 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 { @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 { @Override public void close() throws Exception { + closed = true; in.close(); }