org.apache.cocoon.util
Class PostInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--org.apache.cocoon.util.PostInputStream

public class PostInputStream
extends java.io.InputStream

The class PostInputStream is a wrapper for InputStream associated with POST message. It allows to control read operation, restricting the number of bytes read to the value returned by getContentLen() method.

Version:
CVS $Id: PostInputStream.java,v 1.5 2002/02/22 07:03:57 cziegeler Exp $
Author:
Kinga Dziembowski

Field Summary
static java.lang.String CLASS
          Class name
protected  int m_bytesRead
          The number of bytes read
 
Constructor Summary
PostInputStream()
          Creates a PostInputStream
PostInputStream(java.io.InputStream input, int len)
          Creates a PostInputStream based on a real InputStream object with the specified post message body length.
 
Method Summary
 int available()
          Returns the number of bytes available from this input stream that can be read without the stream blocking.
protected  void checkOpen()
          Checks to see if this stream is closed; if it is, an IOException is thrown.
 void close()
          Closes this input stream by closing the underlying stream and marking this one as closed.
 int getContentLen()
          Returns the post message body length.
 java.io.InputStream getInputStream()
          Returns the underlying input stream.
protected  void init(java.io.InputStream input, int len)
          Sets the underlying input stream and contentLen value .
 boolean markSupported()
          Tests if this input stream supports the mark and reset methods.
 int read()
          Reads the next byte from the input stream.
 int read(byte[] buffer)
           
 int read(byte[] buffer, int offset, int len)
          Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.
 void setInputStream(java.io.InputStream input, int len)
          Sets the underlying input stream and contentLen value .
 long skip(long n)
          See the general contract of the skip method of InputStream.
 java.lang.String toString()
          Returns a String representation of this.
 
Methods inherited from class java.io.InputStream
mark, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS

public static final java.lang.String CLASS
Class name

m_bytesRead

protected int m_bytesRead
The number of bytes read
Constructor Detail

PostInputStream

public PostInputStream()
Creates a PostInputStream

PostInputStream

public PostInputStream(java.io.InputStream input,
                       int len)
                throws java.lang.IllegalArgumentException
Creates a PostInputStream based on a real InputStream object with the specified post message body length. Saves its argument, the input stream m_inputStream, for later use.
Parameters:
input - the underlying input stream.
len - the post message body length.
Throws:
java.lang.IllegalArgumentException - len <= 0.
Method Detail

init

protected void init(java.io.InputStream input,
                    int len)
             throws java.lang.IllegalArgumentException
Sets the underlying input stream and contentLen value .
Parameters:
inputStream - the input stream; can not be null.
len - the post message body length.
Throws:
java.lang.IllegalArgumentException -  

setInputStream

public void setInputStream(java.io.InputStream input,
                           int len)
                    throws java.io.IOException
Sets the underlying input stream and contentLen value .
Parameters:
inputStream - the input stream; can not be null.
len - the post message body length.
Throws:
java.io.IOException -  

getInputStream

public java.io.InputStream getInputStream()
Returns the underlying input stream.
Returns:
inputStream the underlying InputStream.

getContentLen

public int getContentLen()
Returns the post message body length.
Returns:
m_contentLen;

read

public int read()
         throws java.io.IOException
Reads the next byte from the input stream. If the end of the stream has been reached, this method returns -1.
Overrides:
read in class java.io.InputStream
Returns:
the next byte or -1 if at the end of the stream.
Throws:
java.io.IOException -  

read

public int read(byte[] buffer,
                int offset,
                int len)
         throws java.io.IOException
Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.

This method implements the general contract of the corresponding read method of the InputStream class. This method delegetes the read operation to the underlying InputStream implementation class but it controlls the number of bytes read from the stream. In the remote situation the underlying InputStream has no knowledge of the length of the stream and the notion of the "end" is undefined. This wrapper class has a knowledge of the length of data send by the requestor by the means of contentLength. This method returns the number of bytes read and accumulates the total number of bytes read in m_bytesRead. When the m_bytesRead is equal to the specified contentLength value the method returns returns -1 to signal the end of data.

Overrides:
read in class java.io.InputStream
Parameters:
buffer - the byte array to read into; can not be null.
offset - the starting offset in the byte array.
len - the maximum number of bytes to read.
Returns:
the number of bytes read, or -1 if the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read(byte[] buffer)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream

checkOpen

protected void checkOpen()
                  throws java.io.IOException
Checks to see if this stream is closed; if it is, an IOException is thrown.
Throws:
java.io.IOException -  

skip

public long skip(long n)
          throws java.io.IOException
See the general contract of the skip method of InputStream. Delegates execution to the underlying InputStream implementation class. Checks to see if this stream is closed; if it is, an IOException is thrown.
Overrides:
skip in class java.io.InputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.

available

public int available()
              throws java.io.IOException
Returns the number of bytes available from this input stream that can be read without the stream blocking. Delegates execution to the underlying InputStream implementation class.
Overrides:
available in class java.io.InputStream
Returns:
available the number of available bytes.
Throws:
java.io.IOException -  

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods. The markSupported method of BufferedInputStream returns false.
Overrides:
markSupported in class java.io.InputStream
Returns:
a boolean indicating if this stream type supports the mark and reset methods.
See Also:
InputStream.mark(int), InputStream.reset()

close

public void close()
           throws java.io.IOException
Closes this input stream by closing the underlying stream and marking this one as closed.
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException -  

toString

public java.lang.String toString()
Returns a String representation of this.
Overrides:
toString in class java.lang.Object
Returns:
string the String representation of this.


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.