equal
deleted
inserted
replaced
35 * number of bytes off an underlying stream |
35 * number of bytes off an underlying stream |
36 * close() does not close the underlying stream |
36 * close() does not close the underlying stream |
37 */ |
37 */ |
38 |
38 |
39 class FixedLengthInputStream extends LeftOverInputStream { |
39 class FixedLengthInputStream extends LeftOverInputStream { |
40 private int remaining; |
40 private long remaining; |
41 |
41 |
42 FixedLengthInputStream (ExchangeImpl t, InputStream src, int len) { |
42 FixedLengthInputStream (ExchangeImpl t, InputStream src, long len) { |
43 super (t, src); |
43 super (t, src); |
44 this.remaining = len; |
44 this.remaining = len; |
45 } |
45 } |
46 |
46 |
47 protected int readImpl (byte[]b, int off, int len) throws IOException { |
47 protected int readImpl (byte[]b, int off, int len) throws IOException { |
48 |
48 |
49 eof = (remaining == 0); |
49 eof = (remaining == 0L); |
50 if (eof) { |
50 if (eof) { |
51 return -1; |
51 return -1; |
52 } |
52 } |
53 if (len > remaining) { |
53 if (len > remaining) { |
54 len = remaining; |
54 len = (int)remaining; |
55 } |
55 } |
56 int n = in.read(b, off, len); |
56 int n = in.read(b, off, len); |
57 if (n > -1) { |
57 if (n > -1) { |
58 remaining -= n; |
58 remaining -= n; |
59 } |
59 } |
63 public int available () throws IOException { |
63 public int available () throws IOException { |
64 if (eof) { |
64 if (eof) { |
65 return 0; |
65 return 0; |
66 } |
66 } |
67 int n = in.available(); |
67 int n = in.available(); |
68 return n < remaining? n: remaining; |
68 return n < remaining? n: (int)remaining; |
69 } |
69 } |
70 |
70 |
71 public boolean markSupported () {return false;} |
71 public boolean markSupported () {return false;} |
72 |
72 |
73 public void mark (int l) { |
73 public void mark (int l) { |