smbdav
Class LimitInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bysmbdav.LimitInputStream

public class LimitInputStream
extends java.io.FilterInputStream

Limits the amount of data that can be read from the underlying stream to a predefined value. This is used to prevent an XML DOS attack, in which the client sents a very large XML document in a PROPFIND or LOCK request.

Author:
Eric Glass

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
LimitInputStream(java.io.InputStream in, long limit)
          Creates a LimitInputStream from the specified underlying stream, using the provided limit.
 
Method Summary
 void mark(int readLimit)
          Marks the current position in the stream.
 int read()
          Reads a byte of data from the stream.
 int read(byte[] b)
          Reads bytes from the stream into the specified buffer.
 int read(byte[] b, int offset, int length)
          Reads up to the given number of bytes from the stream into the specified buffer starting at the specified offset in the buffer.
 void reset()
          Resets the stream to the previously marked position.
 
Methods inherited from class java.io.FilterInputStream
available, close, markSupported, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LimitInputStream

public LimitInputStream(java.io.InputStream in,
                        long limit)
Creates a LimitInputStream from the specified underlying stream, using the provided limit. Attempts to read after the limit has been reached will result in an EOFException.

Parameters:
in - The underlying input stream.
limit - The maximum number of bytes that can be read from this stream.
Method Detail

read

public int read()
         throws java.io.IOException
Reads a byte of data from the stream.

Returns:
An int containing the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - If an IO error occurs.
java.io.EOFException - If the limit has already been read.

read

public int read(byte[] b)
         throws java.io.IOException
Reads bytes from the stream into the specified buffer.

Parameters:
b - The buffer that will receive the data.
Returns:
An int indicating the number of bytes read, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - If an IO error occurs.
java.io.EOFException - If the limit has already been read.

read

public int read(byte[] b,
                int offset,
                int length)
         throws java.io.IOException
Reads up to the given number of bytes from the stream into the specified buffer starting at the specified offset in the buffer.

Parameters:
b - The buffer that will receive the data.
offset - The offset into the buffer where the data is to be written.
length - The maximum number of bytes to read.
Returns:
An int indicating the number of bytes read, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - If an IO error occurs.
java.io.EOFException - If the limit has already been read.

mark

public void mark(int readLimit)
Marks the current position in the stream. This implementation also marks the amount read, to allow a rollback (if marks are supported by the underlying stream).

Parameters:
readLimit - The amount that can be read before the mark is invalidated.

reset

public void reset()
           throws java.io.IOException
Resets the stream to the previously marked position. This implementation also resets the amount read.

Throws:
java.io.IOException - If the stream has not been marked, or the mark has been invalidated.


Copyright © 2004 Eric Glass