| 61 | } |
| 62 | |
| 63 | public int read(char[] b, int offset, int length) throws IOException { |
| 64 | int count = 0; |
| 65 | |
| 66 | if (position >= limit && length < buffer.length) { |
| 67 | fill(); |
| 68 | } |
| 69 | |
| 70 | if (position < limit) { |
| 71 | int remaining = limit - position; |
| 72 | if (remaining > length) { |
| 73 | remaining = length; |
| 74 | } |
| 75 | |
| 76 | System.arraycopy(buffer, position, b, offset, remaining); |
| 77 | |
| 78 | count += remaining; |
| 79 | position += remaining; |
| 80 | offset += remaining; |
| 81 | length -= remaining; |
| 82 | } |
| 83 | |
| 84 | if (length > 0) { |
| 85 | int c = in.read(b, offset, length); |
| 86 | if (c == -1) { |
| 87 | if (count == 0) { |
| 88 | count = -1; |
| 89 | } |
| 90 | } else { |
| 91 | count += c; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return count; |
| 96 | } |
| 97 | |
| 98 | public void close() throws IOException { |
| 99 | in.close(); |