org.apache.jackrabbit.server.io
Class BoundedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.apache.jackrabbit.server.io.BoundedInputStream
All Implemented Interfaces:
Closeable

public class BoundedInputStream
extends InputStream

This is a stream that will only supply bytes up to a certain length - if its position goes above that, it will stop.

This is useful to wrap ServletInputStreams. The ServletInputStream will block if you try to read content from it that isn't there, because it doesn't know whether the content hasn't arrived yet or whether the content has finished. So, one of these, initialized with the Content-length sent in the ServletInputStream's header, will stop it blocking, providing it's been sent with a correct content length.

Author:
InigoSurguy

Constructor Summary
BoundedInputStream(InputStream in)
           
BoundedInputStream(InputStream in, long size)
          Creates a new BoundedInputStream that wraps the given input stream and limits it to a certain size.
 
Method Summary
 int available()
          
 void close()
          
 boolean isPropagateClose()
           
 void mark(int readlimit)
          
 boolean markSupported()
          
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 void reset()
          
 void setPropagateClose(boolean propagateClose)
           
 long skip(long n)
          
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundedInputStream

public BoundedInputStream(InputStream in,
                          long size)
Creates a new BoundedInputStream that wraps the given input stream and limits it to a certain size.

Parameters:
in - The wrapped input stream
size - The maximum number of bytes to return

BoundedInputStream

public BoundedInputStream(InputStream in)
Method Detail

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException

Overrides:
read in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException

Overrides:
skip in class InputStream
Throws:
IOException

available

public int available()
              throws IOException

Overrides:
available in class InputStream
Throws:
IOException

toString

public String toString()

Overrides:
toString in class Object

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

reset

public void reset()
           throws IOException

Overrides:
reset in class InputStream
Throws:
IOException

mark

public void mark(int readlimit)

Overrides:
mark in class InputStream

markSupported

public boolean markSupported()

Overrides:
markSupported in class InputStream

isPropagateClose

public boolean isPropagateClose()

setPropagateClose

public void setPropagateClose(boolean propagateClose)


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.