summaryrefslogtreecommitdiff
path: root/gnu/java/net/protocol/http
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2006-01-26 00:43:35 +0000
committerTom Tromey <tromey@redhat.com>2006-01-26 00:43:35 +0000
commitbf20436907439f2c47dc22eea41b3d3d5808aa74 (patch)
treec15998f7f0332e419d6abb241d8d450371715ef7 /gnu/java/net/protocol/http
parentb0949fe19e1b1db83526b14c62bd94cebe209ed7 (diff)
downloadclasspath-bf20436907439f2c47dc22eea41b3d3d5808aa74.tar.gz
* gnu/java/net/protocol/http/ChunkedInputStream.java (read):
Fixed calculation of number of bytes to read. (size, count, meta, eof): Document.
Diffstat (limited to 'gnu/java/net/protocol/http')
-rw-r--r--gnu/java/net/protocol/http/ChunkedInputStream.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/gnu/java/net/protocol/http/ChunkedInputStream.java b/gnu/java/net/protocol/http/ChunkedInputStream.java
index a4487d146..92bc1a014 100644
--- a/gnu/java/net/protocol/http/ChunkedInputStream.java
+++ b/gnu/java/net/protocol/http/ChunkedInputStream.java
@@ -1,5 +1,5 @@
/* ChunkedInputStream.java --
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -55,9 +55,16 @@ public class ChunkedInputStream
private static final byte CR = 0x0d;
private static final byte LF = 0x0a;
+ /** Size of the chunk we're reading. */
int size;
+ /** Number of bytes we've read in this chunk. */
int count;
+ /**
+ * True when we should read meta-information, false when we should
+ * read data.
+ */
boolean meta;
+ /** True when we've hit EOF. */
boolean eof;
Headers headers;
@@ -142,17 +149,22 @@ public class ChunkedInputStream
}
else
{
- int diff = length - offset;
- int max = size - count;
- max = (diff < max) ? diff : max;
- int len = (max > 0) ? in.read(buffer, offset, max) : 0;
+ int canRead = Math.min(size - count, length);
+ int len = in.read(buffer, offset, canRead);
+ if (len == -1)
+ {
+ // This is an error condition but it isn't clear what we
+ // should do with it.
+ eof = true;
+ return -1;
+ }
count += len;
if (count == size)
{
// Read CRLF
int c1 = in.read();
int c2 = in.read();
- if (c1 == -1 && c2 == -1)
+ if (c1 == -1 || c2 == -1)
{
// EOF before CRLF: bad, but ignore
eof = true;