X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Fio%2FLimitedInputStream.java;h=68e5d16234b72ffd3060a1de34195981945dd040;hb=c4ecc65b0832a2edce1a043db39a7c678e218af9;hp=8e23f24026454f32419248a4e6c792b9169c8375;hpb=87607d6d051b828515044b71a7ddb549e13deae1;p=jSite2.git
diff --git a/src/net/pterodactylus/util/io/LimitedInputStream.java b/src/net/pterodactylus/util/io/LimitedInputStream.java
index 8e23f24..68e5d16 100644
--- a/src/net/pterodactylus/util/io/LimitedInputStream.java
+++ b/src/net/pterodactylus/util/io/LimitedInputStream.java
@@ -1,6 +1,7 @@
/**
* © 2008 INA Service GmbH
*/
+
package net.pterodactylus.util.io;
import java.io.FilterInputStream;
@@ -10,9 +11,8 @@ import java.io.InputStream;
/**
* A wrapper around an {@link InputStream} that only supplies a limit number of
* bytes from the underlying input stream.
- *
+ *
* @author David Roden
- * @version $Id$
*/
public class LimitedInputStream extends FilterInputStream {
@@ -22,7 +22,7 @@ public class LimitedInputStream extends FilterInputStream {
/**
* Creates a new LimitedInputStream that supplies at most
* length
bytes from the given input stream.
- *
+ *
* @param inputStream
* The input stream
* @param length
@@ -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));
@@ -82,11 +85,9 @@ public class LimitedInputStream extends FilterInputStream {
}
/**
- * {@inheritDoc}
- *
- * This method does nothing, as {@link #mark(int)} and {@link #reset()} are
- * not supported.
- *
+ * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
+ * {@link #reset()} are not supported.
+ *
* @see java.io.FilterInputStream#mark(int)
*/
@Override
@@ -96,7 +97,7 @@ public class LimitedInputStream extends FilterInputStream {
/**
* {@inheritDoc}
- *
+ *
* @see java.io.FilterInputStream#markSupported()
* @return false
*/
@@ -106,11 +107,9 @@ public class LimitedInputStream extends FilterInputStream {
}
/**
- * {@inheritDoc}
- *
- * This method does nothing, as {@link #mark(int)} and {@link #reset()} are
- * not supported.
- *
+ * {@inheritDoc} This method does nothing, as {@link #mark(int)} and
+ * {@link #reset()} are not supported.
+ *
* @see java.io.FilterInputStream#reset()
*/
@Override
@@ -121,7 +120,7 @@ public class LimitedInputStream extends FilterInputStream {
/**
* Consumes the input stream, i.e. read all bytes until the limit is
* reached.
- *
+ *
* @throws IOException
* if an I/O error occurs
*/