com.ibm.wbi
Class MegWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--com.ibm.wbi.MegWriter

public class MegWriter
extends java.io.Writer

A MegWriter is used by a Meg to write out character or String data to the next Meg. A MegWriter is obtained by calling com.ibm.wbi.RequestEvent.getMegWriter(). A MegWriter will automatically perform any necessary encoding into bytes for network transport. The correct encoding is automatically selected based on the document's Content-Type at the time getMegWriter() is called. If you intend to have your Meg change the document's encoding, you should change the "Content-Type: text/*; charset=xxx" header to the desired charset before you call getMegWriter(). This will have the desired effect. If the document's Content-Type indicates that it is not character data, e.g., "image/gif", getMegWriter() will throw a NotCharDataException.

See Also:
MegOutputStream, RequestEvent.getMegWriter()

Field Summary
protected  java.io.OutputStreamWriter w
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
MegWriter(MegOutputStream out, java.lang.String encoding)
          Creates a MegWriter from an existing MegOutputStream.
 
Method Summary
 void close()
          Close the stream, flushing it first.
 void flush()
          Flush the stream.
 void write(char c)
          Write one character to the stream.
 void write(char[] cbuf)
          Write characters from an array to the stream.
 void write(char[] cbuf, int off, int len)
          Write characters from an array to the stream.
 
Methods inherited from class java.io.Writer
write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

w

protected java.io.OutputStreamWriter w
Constructor Detail

MegWriter

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

write

public void write(char c)
           throws java.io.IOException
Write one character to the stream.
Parameters:
c - The character to write.
Throws:
java.io.IOException - If an error occurs.

write

public void write(char[] cbuf)
           throws java.io.IOException
Write characters from an array to the stream.
Overrides:
write in class java.io.Writer
Parameters:
cbuf - The characters to write.
Throws:
java.io.IOException - If an error occurs.

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Write characters from an array to the stream.
Overrides:
write in class java.io.Writer
Parameters:
cbuf - The characters to write.
off - The offset from which to start writing characters.
len - The number of characters to write.
Throws:
java.io.IOException - If an error occurs.

flush

public void flush()
           throws java.io.IOException
Flush the stream.
Overrides:
flush in class java.io.Writer
Throws:
java.io.IOException - If an error occurs.

close

public void close()
           throws java.io.IOException
Close the stream, flushing it first. Closing an already-closed stream has no effect.
Overrides:
close in class java.io.Writer
Throws:
java.io.IOException - If an error occurs.