org.enhydra.servlet.connectionMethods.EnhydraDirector
Class EnhydraDirectorOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjavax.servlet.ServletOutputStream
          extended byorg.enhydra.servlet.connectionMethods.EnhydraDirector.EnhydraDirectorOutputStream

public class EnhydraDirectorOutputStream
extends javax.servlet.ServletOutputStream

OutputStream interface for the Enhydra connection method.

Implemention of ServletOutputStream to be passed to servlets to allow them to send response data to the client.

This class automatically wrappers a lower level output stream in a BufferedOutputStream if buffering is requested by the servlet.

Version:
$Revision: 1.2 $
Author:
John Marco
See Also:
EnhydraResponse, ServletOutputStream

Constructor Summary
EnhydraDirectorOutputStream(EnhydraDirectorConnection conn)
          Construct an output stream associate with a response object.
 
Method Summary
 void close()
           
 void flush()
           
 int getBufferSize()
          Get the buffer size.
 void print(char c)
          Writes a character to response data using simple Latin-1 encoding.
 void print(java.lang.String s)
          Writes a string to response data using simple ASCII-8 encoding.
 void reset()
          Resets the underlying output stream, discarding any buffers.
 void setBufferSize(int size)
          Set the buffer size.
 void write(byte[] bytes)
          Write an array of bytes to this output stream.
 void write(byte[] bytes, int off, int len)
          Write an array of bytes to this output stream.
 void write(int b)
          Write a single byte of response data.
 
Methods inherited from class javax.servlet.ServletOutputStream
print, print, print, print, print, println, println, println, println, println, println, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnhydraDirectorOutputStream

public EnhydraDirectorOutputStream(EnhydraDirectorConnection conn)
                            throws java.io.IOException
Construct an output stream associate with a response object.

Parameters:
conn - EnhydraDirector protocol driver instance.
Method Detail

setBufferSize

public void setBufferSize(int size)
Set the buffer size.

Sets the buffer size for this output stream. If less than or equal to zero, no buffering is done and output is sent directly to the protocol engine's output methods.

This method throws an IllegalStateException if it is called after the first write to response output.

Parameters:
size - The size of the buffer, or 0 for no buffering.
Throws:
java.lang.IllegalStateException - If data has already been written.

getBufferSize

public int getBufferSize()
Get the buffer size.

Gets the buffer size for this output stream. If less than or equal to zero, no buffering is done and output is sent directly to the protocol engine's output methods.

Returns:
The size of the buffer, or 0 for no buffering.

write

public void write(int b)
           throws java.io.IOException
Write a single byte of response data.

This method is extremely inefficient, since it sends a separate packet for each outgoing response byte. Servlets should pass this output stream to the constructor of a new BufferedOutputStream if the single byte write() call is going to be used frequently.

Parameters:
b - Integer with a value between 0 and 255, inclusive.
Throws:
java.io.IOException - If an I/O error occurs.

write

public void write(byte[] bytes,
                  int off,
                  int len)
           throws java.io.IOException
Write an array of bytes to this output stream.

Parameters:
bytes - Array of byte data to write to the stream.
off - Starting offset in the array.
len - Number of bytes to write.
Throws:
java.io.IOException - If an I/O error occurs.

write

public void write(byte[] bytes)
           throws java.io.IOException
Write an array of bytes to this output stream.

Parameters:
bytes - Array of byte data to write to the stream.
Throws:
java.io.IOException - If an I/O error occurs.

print

public void print(java.lang.String s)
           throws java.io.IOException
Writes a string to response data using simple ASCII-8 encoding.

Sigh

This really does not belong at this level. The correct solution would have been to have servlets pass a plain, simple well defined binary OutputStream to a PrintStream or PrintWriter if they wanted to have fully encoded string writing.

This implementation supports only simple 8 bit ASCII encoding. If non-ASCII unicode characters are used, they WILL be truncated. The correct solution in this case is to use the appropriate PrintStream or PrintWriter classes to do the string-to-binary encoding at a higher level.

String-to-binary encoding is extremely slow.

Parameters:
s - The string to write.
Throws:
java.io.IOException - if an I/O error has occurred
See Also:
ServletOutputStream.print(java.lang.String)

print

public void print(char c)
           throws java.io.IOException
Writes a character to response data using simple Latin-1 encoding.

Sigh

This really does not belong at this level. The correct solution would have been to have servlets pass a plain, simple well defined binary OutputStream to a PrintStream or PrintWriter if they wanted to have fully encoded string writing.

This implementation supports only simple 8 bit ASCII encoding. If non-ASCII unicode characters are used, they WILL be truncated. The correct solution in this case is to use the appropriate PrintStream or PrintWriter classes to do the string-to-binary encoding at a higher level.

String-to-binary encoding is extremely slow.

Parameters:
c - The character to write.
Throws:
java.io.IOException - if an I/O error has occurred
See Also:
ServletOutputStream.print(java.lang.String)

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

reset

public void reset()
           throws java.lang.IllegalStateException
Resets the underlying output stream, discarding any buffers.

Throws:
java.lang.IllegalStateException - If the stream is not buffered, or if buffer data has already been flushed/written to the connection.