com.jalios.io
Class SizeLimitInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by com.jalios.io.SizeLimitInputStream
All Implemented Interfaces:
Closeable

public class SizeLimitInputStream
extends FilterInputStream

InputStream Filter that will throw an SizeLimitExceededException if the wrapped stream exceed the byte count specified in constructor.

Version:
$Revision: 27751 $

Nested Class Summary
 class SizeLimitInputStream.SizeLimitExceededException
          Signals that a size limit has been reach during an I/O operation.
 
Field Summary
static String REVISION
           
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
SizeLimitInputStream(InputStream in, long limit)
          Constructs a new SizeLimitInputStreamFilter.
 
Method Summary
 int read()
          Reads the next byte of data adding to the count of bytes received if a byte is successfully read.
 int read(byte[] b)
          Reads a number of bytes into the byte array, keeping count of the number read.
 int read(byte[] b, int off, int len)
          Reads a number of bytes into the byte array at a specific offset, keeping count of the number read.
 long skip(long length)
          Skips the stream over the specified number of bytes, adding the skipped amount to the count.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

SizeLimitInputStream

public SizeLimitInputStream(InputStream in,
                            long limit)
Constructs a new SizeLimitInputStreamFilter.

Parameters:
in - the InputStream to delegate to
limit - the number of bytes accepted by the filter before throwing an exception
Method Detail

read

public int read(byte[] b)
         throws IOException
Reads a number of bytes into the byte array, keeping count of the number read.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read, not null
Returns:
the total number of bytes read into the buffer, -1 if end of stream
Throws:
IOException - if an I/O error occurs
See Also:
InputStream.read(byte[])

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Reads a number of bytes into the byte array at a specific offset, keeping count of the number read.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read, not null
off - the start offset in the buffer
len - the maximum number of bytes to read
Returns:
the total number of bytes read into the buffer, -1 if end of stream
Throws:
IOException - if an I/O error occurs
See Also:
InputStream.read(byte[], int, int)

read

public int read()
         throws IOException
Reads the next byte of data adding to the count of bytes received if a byte is successfully read.

Overrides:
read in class FilterInputStream
Returns:
the byte read, -1 if end of stream
Throws:
IOException - if an I/O error occurs
See Also:
InputStream.read()

skip

public long skip(long length)
          throws IOException
Skips the stream over the specified number of bytes, adding the skipped amount to the count.

Overrides:
skip in class FilterInputStream
Parameters:
length - the number of bytes to skip
Returns:
the actual number of bytes skipped
Throws:
IOException - if an I/O error occurs
See Also:
InputStream.skip(long)


Copyright © 2001-2010 Jalios SA. All Rights Reserved.