NextableInputStream: better skip() + more tests
[nikiroo-utils.git] / src / be / nikiroo / utils / NextableInputStream.java
index 7ced59804b02ce5ccad360cf8c193ef1992765f2..b5374a1329b88ce4944412830f4edb552c818b17 100644 (file)
@@ -277,8 +277,21 @@ public class NextableInputStream extends InputStream {
 
        @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