do not access underlying input stream if remaining == 0
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 18:15:45 +0000 (18:15 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 18:15:45 +0000 (18:15 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@732 c3eda9e8-030b-0410-8277-bc7414b0a119

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));