do not access underlying input stream if remaining == 0
[jSite2.git] / src / net / pterodactylus / util / io / LimitedInputStream.java
index 8e23f24..284d53d 100644 (file)
@@ -38,6 +38,9 @@ public class LimitedInputStream extends FilterInputStream {
         */
        @Override
        public synchronized int available() throws IOException {
+               if (remaining == 0) {
+                       return 0;
+               }
                return (int) Math.min(super.available(), Math.min(Integer.MAX_VALUE, remaining));
        }
 
@@ -73,7 +76,7 @@ public class LimitedInputStream extends FilterInputStream {
         */
        @Override
        public synchronized long skip(long n) throws IOException {
-               if (n < 0) {
+               if ((n < 0)  || (remaining == 0)) {
                        return 0;
                }
                long skipped = super.skip(Math.min(n, remaining));