com.ibm.wbi
Class MegReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--com.ibm.wbi.MegReader

public class MegReader
extends java.io.Reader

A MegReader is a character-based version of a MegInputStream. A MegInputStream can be used to read any kind of stream as bytes. A MegReader can, and should, be used to read a character-based stream as characters. Using a MegReader relieves the user of the burden of determining the correct encoding to use to convert between bytes and Unicode characters. The encoding will be automatically determined based on the document headers and other information. A MegReader is obtained by calling com.ibm.wbi.RequestEvent.getMegReader(). If the underlying stream is not character data, for example, a GIF image, getMegReader() will throw a NotCharDataException.

See Also:
MegInputStream, RequestEvent.getMegReader()

Field Summary
protected  java.io.InputStreamReader r
           
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
MegReader(MegInputStream in, java.lang.String encoding)
          Creates a MegReader from an existing MegInputStream.
 
Method Summary
 void close()
          Closes the stream.
 void mark(int limit)
          Marks the stream at its present position.
 boolean markSupported()
          Tells whether mark()/reset()/preserveMark() are supported on this stream.
 int read()
          Read a single character, blocking until a character is available, the end of the stream is reached, or an exception occurs.
 int read(char[] cbuf)
          Read characters into an array.
 int read(char[] cbuf, int off, int len)
          Read characters into an array.
 void reset()
          Resets the stream to its previously marked position, so that any characters read in between calling mark() and reset() will be read again.
 
Methods inherited from class java.io.Reader
ready, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

r

protected java.io.InputStreamReader r
Constructor Detail

MegReader

public MegReader(MegInputStream in,
                 java.lang.String encoding)
          throws java.io.UnsupportedEncodingException
Creates a MegReader from an existing MegInputStream. The character encoding must be specified.
Parameters:
in - The MegInputStream from which characters are to be read.
encoding - The encoding used for those characters.
See Also:
RequestInfo.getRequestCharEncoding(), RequestInfo.getResponseCharEncoding()
Method Detail

read

public int read()
         throws java.io.IOException
Read a single character, blocking until a character is available, the end of the stream is reached, or an exception occurs.
Overrides:
read in class java.io.Reader
Returns:
The character read, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - If an error occurs.

read

public int read(char[] cbuf)
         throws java.io.IOException
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
Overrides:
read in class java.io.Reader
Parameters:
cbuf - The array to read characters into.
Returns:
The number of characters read, or -1 if the end of stream is reached.
Throws:
java.io.IOException - if an error occurs.

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
Overrides:
read in class java.io.Reader
Parameters:
cbuf - The array to read characters into.
off - The offset to start putting characters into the array.
len - The maximum number of characters to read.
Returns:
The number of characters read, or -1 if the end of stream is reached.
Throws:
java.io.IOException - if an error occurs.

close

public void close()
           throws java.io.IOException
Closes the stream. Closing an already-closed stream has no effect.
Overrides:
close in class java.io.Reader
Throws:
java.io.IOException - If an error occurs.

markSupported

public boolean markSupported()
Tells whether mark()/reset()/preserveMark() are supported on this stream.
Overrides:
markSupported in class java.io.Reader
Returns:
true if the methods are supported, false otherwise.

mark

public void mark(int limit)
          throws java.io.IOException
Marks the stream at its present position. A subsequent call to reset() will reset the stream to this position unless the mark has been invalidated.
Overrides:
mark in class java.io.Reader
Parameters:
limit - The maximum number of characters that may be read from the stream without invalidating the mark.
Throws:
java.io.IOException - If this stream does not support mark() or some other error occurs.

reset

public void reset()
           throws java.io.IOException
Resets the stream to its previously marked position, so that any characters read in between calling mark() and reset() will be read again.
Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException - If the stream has not been marked, the mark has been invalidated, the stream does not support reset() or some other error occurs.