Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.enhydra.servlet.connectionMethods.EnhydraDirector
Class EnhydraDirectorOutputStream  view EnhydraDirectorOutputStream download EnhydraDirectorOutputStream.java

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

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.4.2.1.2.1 $

Field Summary
private  int bufSize
          Buffer size.
private  EnhydraDirectorConnection conn
          Internal EnhydraDirector protocol driver instance.
private static boolean debug
          Debug flag
private  boolean isFirstWrite
          Whether headers have been written.
private  java.io.OutputStream os
          The underlying EnhydraDirectorProtoOutputStream.
private  java.io.OutputStream out
          The actual OutputStream.
 
Fields inherited from class javax.servlet.ServletOutputStream
 
Constructor Summary
EnhydraDirectorOutputStream(EnhydraDirectorConnection conn)
          Construct an output stream associate with a response object.
 
Method Summary
 void close()
          Commits headers and immediately sends any outgoing data over the connection.
private  void firstWrite()
          Internal method to be called upon the first write of data.
 void flush()
          Closes this output stream and releases any system resources associated with the stream.
 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
 

Field Detail

conn

private EnhydraDirectorConnection conn
Internal EnhydraDirector protocol driver instance.


out

private java.io.OutputStream out
The actual OutputStream. Not set until buffering is finalized.


os

private java.io.OutputStream os
The underlying EnhydraDirectorProtoOutputStream.


isFirstWrite

private boolean isFirstWrite
Whether headers have been written. Saves a method call.


bufSize

private int bufSize
Buffer size. If less than or equal to zero, no buffering.


debug

private static final boolean debug
Debug flag

See Also:
Constant Field Values
Constructor Detail

EnhydraDirectorOutputStream

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

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.


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.


firstWrite

private void firstWrite()
                 throws java.io.IOException
Internal method to be called upon the first write of data.

Sets up the output stream as either a buffered or unbuffered stream depending on the buffer size.

Note. Does NOT commit() the connection, since we only send headers when data bytes are about to be actually sent over the wire.


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.


write

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


write

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


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.


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.


close

public void close()
           throws java.io.IOException
Commits headers and immediately sends any outgoing data over the connection.


flush

public void flush()
           throws java.io.IOException
Closes this output stream and releases any system resources associated with the stream.


reset

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