package webraveler.io; import java.io.*; /* InputStream for when we have a Transfer-length or Content-length header telling us how long the body is.*/ public class FixedLengthInputStream extends InputStream{ /* instance variables */ int bytesAllowed; int bytesRead; InputStream input; /* constructors */ public FixedLengthInputStream(InputStream in, int length){ bytesAllowed= length; bytesRead= 0; input= in; } public int read() throws IOException{ if( bytesRead < bytesAllowed ){ bytesRead++; return input.read(); } else { return -1; } } public void close() throws IOException{ } }