From 6886a8b765ab7d98a07824228a24a767d7071eef Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 7 Oct 2009 11:41:13 +0000 Subject: [PATCH] Fixed issue: NETTY-234 ChunkedStream usage fails with NegativeArraySize error * Worked around an interesting JDK issue where InputStream.available() returns a negative value --- .../org/jboss/netty/handler/stream/ChunkedStream.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/netty/handler/stream/ChunkedStream.java b/src/main/java/org/jboss/netty/handler/stream/ChunkedStream.java index 6d566a6960..0857167efd 100644 --- a/src/main/java/org/jboss/netty/handler/stream/ChunkedStream.java +++ b/src/main/java/org/jboss/netty/handler/stream/ChunkedStream.java @@ -93,7 +93,13 @@ public class ChunkedStream implements ChunkedInput { return null; } - final int chunkSize = Math.min(this.chunkSize, in.available()); + final int availableBytes = in.available(); + final int chunkSize; + if (availableBytes <= 0) { + chunkSize = this.chunkSize; + } else { + chunkSize = Math.min(this.chunkSize, in.available()); + } final byte[] chunk = new byte[chunkSize]; int readBytes = 0; for (;;) {