info.informatica.io
Class LimitedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by info.informatica.io.LimitedInputStream
All Implemented Interfaces:
Closeable

public class LimitedInputStream
extends FilterInputStream

An InputStream with resource limit.

This class allows to have control over the amount of bytes flowing through the stream.

Version:
1.02
Author:
amengual at informatica dot info

Constructor Summary
LimitedInputStream(InputStream is)
          Creates a LimitedInputStream with the default value of 64 MB.
LimitedInputStream(InputStream is, int maxsize)
          Creates a LimitedInputStream with the specified size.
 
Method Summary
 int getBytesTransferred()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 int write(OutputStream os)
           
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LimitedInputStream

public LimitedInputStream(InputStream is,
                          int maxsize)
Creates a LimitedInputStream with the specified size.

Parameters:
is - the InputStream.
maxsize - the max amount of bytes that this stream is allowed to read.

LimitedInputStream

public LimitedInputStream(InputStream is)
Creates a LimitedInputStream with the default value of 64 MB.

Parameters:
is - the InputStream.
Method Detail

write

public int write(OutputStream os)
          throws IOException
Throws:
IOException

getBytesTransferred

public int getBytesTransferred()

read

public int read()
         throws IOException
Overrides:
read in class FilterInputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class FilterInputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class FilterInputStream
Throws:
IOException