…lines 1–135 unchanged (135 lines)
136
137 /**
138 * {@inheritDoc}
139 *
140 * @throws IllegalArgumentException if the provided skip length is negative
141 */
142 @Override
143 public long skip(long n) throws IOException {
144 if (n < 0) {
145 throw new IllegalArgumentException("Negative skip length");
146 }
147
148 // skip in chunks of 512 bytes
149 final byte[] b = new byte[512];
150 final int max = (int) Math.min(n, Integer.MAX_VALUE);
151 int total = 0;
152
153 while (total < max) {
154 int len = max - total;
155 if (len > b.length) {
156 len = b.length;
157 }
158 len = read(b, 0, len);
159 if (len == EOF) {
160 break;
161 }
162 total += len;
163 }
164
165 return total;
166 }
167
168 /**
169 * {@inheritDoc}
170 *
171 * @return <code>0</code> if the {@link InputStream} has reached <code>EOF</code>,
172 * <code>1</code> otherwise
173 */
174 public int available() throws IOException {
175 // Note: the logic is similar to the InflaterInputStream:
176 // as long as we have not reached EOF, indicate that there is more
177 // data available. As we do not know for sure how much data is left,
178 // just return 1 as a safe guess.
179
180 // use the EOF flag of the underlying codec instance
181 if (baseNCodec.eof) {
182 return 0;
183 } else {
184 return 1;
185 }
186 }
187}
188