com.ibm.wbi
Class MegInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--com.ibm.wbi.MegInputStream

public abstract class MegInputStream
extends java.io.InputStream

The InputStream used by a Meg to read streamed request data.


Constructor Summary
MegInputStream()
          Construct a new MegInputStream.
 
Method Summary
abstract  int available()
          Determine amount of bytes currently available.
abstract  void close()
          Close the input stream.
abstract  java.lang.String getRequestString()
          An implementation specific string description of the request stream read from the input stream.
abstract  long getTimeout()
          Access the timeout value for read operations.
abstract  boolean isClosed()
          Determines if the input stream is closed.
abstract  int peek()
          Peek a byte from the input stream.
abstract  int peek(byte[] buf)
          Peek bytes from the input stream filling the specified byte array.
abstract  int peek(byte[] buf, int offset, int length)
          Peek multiple bytes from the input stream.
abstract  int peek(ByteStore buf, int length)
          Peek bytes from the input stream filling the specified byte buffer.
 void preserveMark()
          If a mark (see java.io.InputStream.mark()) is in effect on this stream, throw an IOException rather than undoing the mark if the "readlimit" is about to be passed.
abstract  int read()
          Read a byte from the input stream.
abstract  int read(byte[] buf)
          Read bytes from the input stream filling the specified byte array.
abstract  int read(byte[] buf, int offset, int length)
          Read multiple bytes from the input stream.
abstract  int read(ByteStore buf, byte[] temp)
          Read bytes from the input stream filling the specified byte buffer.
abstract  int read(ByteStore buf, int length)
          Read bytes from the input stream filling the specified byte buffer.
abstract  void setTimeout(long timeout)
          Set a timeout value for read operations.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MegInputStream

public MegInputStream()
Construct a new MegInputStream.
Method Detail

read

public abstract int read()
                  throws java.io.IOException
Read a byte from the input stream. Blocks if no data available and end of stream not yet reached. The value of byte is as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.
Overrides:
read in class java.io.InputStream
Returns:
The next byte from the stream.
Throws:
java.io.IOException - If stream closed.
MarkPreservedException - If read would invalidate preserved mark

read

public abstract int read(byte[] buf,
                         int offset,
                         int length)
                  throws java.io.IOException
Read multiple bytes from the input stream. Blocks if no data available and end of stream not yet reached.
Overrides:
read in class java.io.InputStream
Parameters:
buf - The byte buffer to populate.
offset - The offset in buf to starting writing to.
length - The amount of bytes to write.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.
MarkPreservedException - If read would invalidate preserved mark

read

public abstract int read(byte[] buf)
                  throws java.io.IOException
Read bytes from the input stream filling the specified byte array. Blocks if no data available and end of stream not yet reached.
Overrides:
read in class java.io.InputStream
Parameters:
buf - The byte buffer to populate.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed or mark would not be preserved.
MarkPreservedException - If read would invalidate preserved mark

read

public abstract int read(ByteStore buf,
                         int length)
                  throws java.io.IOException
Read bytes from the input stream filling the specified byte buffer. Blocks if no data available and end of stream not yet reached.
Parameters:
buf - The byte store to populate.
length - The amount to read.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.
MarkPreservedException - If read would invalidate preserved mark

read

public abstract int read(ByteStore buf,
                         byte[] temp)
                  throws java.io.IOException
Read bytes from the input stream filling the specified byte buffer. Blocks if no data available and end of stream not yet reached.
Parameters:
buf - The byte store to populate.
temp - Temporary buffer of size to read.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.
MarkPreservedException - If read would invalidate preserved mark

peek

public abstract int peek()
                  throws java.io.IOException
Peek a byte from the input stream. Blocks if no data available and end of stream not yet reached.
Returns:
The next byte from the stream.
Throws:
java.io.IOException - If stream closed.

peek

public abstract int peek(byte[] buf,
                         int offset,
                         int length)
                  throws java.io.IOException
Peek multiple bytes from the input stream. Blocks if no data available and end of stream not yet reached.
Parameters:
buf - The byte buffer to populate.
offset - The offset in buf to starting writing to.
length - The amount of bytes to write.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.

peek

public abstract int peek(byte[] buf)
                  throws java.io.IOException
Peek bytes from the input stream filling the specified byte array. Blocks if no data available and end of stream not yet reached.
Parameters:
buf - The byte buffer to populate.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.

peek

public abstract int peek(ByteStore buf,
                         int length)
                  throws java.io.IOException
Peek bytes from the input stream filling the specified byte buffer. Blocks if no data available and end of stream not yet reached.
Parameters:
buf - The byte store to populate.
length - The amount to read.
Returns:
The amount of bytes read, or -1 if no more bytes available to read.
Throws:
java.io.IOException - If stream closed.

setTimeout

public abstract void setTimeout(long timeout)
Set a timeout value for read operations. Reads will not block longer than the timeout time. If a timeout occurs, then an InterruptedIOException will be thrown.
Parameters:
timeout - The maximum time to block for read operations, in milliseconds. A value of zero (the default) means to never timeout.

getTimeout

public abstract long getTimeout()
Access the timeout value for read operations.
Returns:
The maximum time to block for read operations, in milliseconds. A value of zero means to never timeout.

close

public abstract void close()
Close the input stream. If the stream is already closed, this method has not effect.
Overrides:
close in class java.io.InputStream

isClosed

public abstract boolean isClosed()
Determines if the input stream is closed.
Returns:
true if stream closed; else false.

available

public abstract int available()
                       throws java.io.IOException
Determine amount of bytes currently available.
Overrides:
available in class java.io.InputStream
Returns:
The amount of bytes available.
Throws:
java.io.IOException - If stream closed.

getRequestString

public abstract java.lang.String getRequestString()
An implementation specific string description of the request stream read from the input stream. This string holds no other value other than to relay potential debugging information to a user (for use in a GUI for example). No guarantees are made about the protocol of the string, but it can be expected that it would have relevant information pertaining to the request. For example, an HTTP/1.0 request may have a request string such as "http://www.wbi.com/index.htm [Friday, September 17, 1999 at 01:20:15]".
Returns:
String representation of the request.

preserveMark

public void preserveMark()
                  throws java.io.IOException
If a mark (see java.io.InputStream.mark()) is in effect on this stream, throw an IOException rather than undoing the mark if the "readlimit" is about to be passed. This can be useful if you want to, e.g., search for a TITLE tag in the first 10k of a document, but if you don't find it by then, you're not interested. Calling preserveMark() before you start reading means that if you pass 10k, you'll get a MarkPreservedException and the mark will still be in place, enabling you to legally then throw a RequestRejectedException. Classes extending MegInputStream MUST implement preserveMark() IF AND ONLY IF they also implement mark(), reset(), and markSupported() (methods of java.io.InputStream).