/**
* Check if this stream is totally spent (no more data to read or to
* process).
+ * <p>
+ * Note: an empty stream that is still not started will return FALSE, as we
+ * don't know yet if it is empty.
*
* @return TRUE if it is
*/
while (hasMoreData() && done < blen) {
preRead();
if (hasMoreData()) {
- for (int i = pos; i < blen && i < len; i++) {
- b[boff + done] = buffer[i];
- pos++;
- done++;
+ int now = Math.min(blen, len) - pos;
+ if (now > 0) {
+ System.arraycopy(buffer, pos, b, boff, now);
+ pos += now;
+ done += now;
}
}
}
@Override
public long skip(long n) throws IOException {
- // TODO Auto-generated method stub
- return super.skip(n);
+ if (n <= 0) {
+ return 0;
+ }
+
+ long skipped = 0;
+ while (hasMoreData() && n > 0) {
+ preRead();
+
+ long inBuffer = Math.min(n, available());
+ pos += inBuffer;
+ n -= inBuffer;
+ skipped += inBuffer;
+ }
+
+ return skipped;
}
@Override
}
// buffer must be > search
- static private boolean startsWith(byte[] search, byte[] buffer,
- int offset) {
+ static private boolean startsWith(byte[] search, byte[] buffer, int offset) {
boolean same = true;
for (int i = 0; i < search.length; i++) {
if (search[i] != buffer[offset + i]) {