com.infoengine.object
Class IeMultipartOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.infoengine.object.IeMultipartOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class IeMultipartOutputStream
extends java.io.OutputStream

This class defines and manages the content and format of output streams that flow between components of the Info*Engine architecture.


Constructor Summary
IeMultipartOutputStream(java.io.OutputStream out)
          Constructs an Info*Engine multipart output stream by wrapping a basic output stream.
IeMultipartOutputStream(java.io.OutputStream out, IeMultipartInputStream in)
          Constructs an Info*Engine multipart output stream by wrapping a basic output stream and obtaining boundary and content type information from an Info*Engine servlet multipart input stream.
IeMultipartOutputStream(java.io.OutputStream out, java.lang.String boundary)
          Constructs an Info*Engine multipart output stream by wrapping a basic output stream and providing a specific boundary string for separating the objects transmitted in the stream.
 
Method Summary
 void close()
          Closes the output stream and releases resources allocated to it.
 boolean eofWritten()
          Tests whether an end of file indication (MIME termination boundary) has been written to the stream.
 void flush()
          Flushes any output buffered on the output stream.
 void print(java.lang.String data)
          Prints a string to the output stream.
 void println(java.lang.String data)
          Prints a string to the output stream with a CR/LF sequence appended.
 void setCharacterSet(java.lang.String encoding)
          Sets the character set encoding to use when converting Info*Engine request objects to XML.
 void setForceEncoding(java.lang.String encoding)
          Sets an encoding to use when writing text output.
 void write(byte[] b)
          Writes an array of bytes to the output stream.
 void write(byte[] b, int off, int len)
          Writes a segment of an array of bytes to the output stream.
 void write(int b)
          Writes a single byte to the output stream.
 void write(java.lang.String name, java.lang.String filename, java.lang.String contentType)
          Writes a MIME content object header to the output stream.
 void write(java.lang.String data, java.lang.String name, java.lang.String filename, java.lang.String contentType)
          Writes one content object of a MIME multipart object to the output stream.
 void writeBlob(java.io.InputStream content, java.lang.String name, java.lang.String filename, java.lang.String contentType)
          Writes one content object of a MIME multipart object to the output stream.
 void writeBlob(java.io.InputStream content, java.lang.String name, java.lang.String filename, java.lang.String contentType, boolean flag)
          Deprecated. Use writeBlob() without the flag argument instead.
 void writeEOF()
          Writes a MIME multipart object termination boundary to the output stream.
 void writeRequest(IeRequest request)
          Writes an Info*Engine request object to the output stream.
 void writeRequest(IeRequest request, java.lang.String contentType)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeRequest(IeRequest request, java.lang.String contentType, boolean exception)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, java.lang.String contentType)
          Writes an Info*Engine VDB object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, java.lang.String contentType, boolean exception)
          Writes an Info*Engine VDB object to the output stream serializing according to contentType.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IeMultipartOutputStream

public IeMultipartOutputStream(java.io.OutputStream out)
                        throws java.io.IOException
Constructs an Info*Engine multipart output stream by wrapping a basic output stream.

Parameters:
out - The basic output stream to be wrapped.
Throws:
java.io.IOException - if the class instance is not initialized successfully.

IeMultipartOutputStream

public IeMultipartOutputStream(java.io.OutputStream out,
                               java.lang.String boundary)
                        throws java.io.IOException
Constructs an Info*Engine multipart output stream by wrapping a basic output stream and providing a specific boundary string for separating the objects transmitted in the stream.

Parameters:
out - The basic output stream to be wrapped.
boundary - The boundary string to be used in separating objects transmitted in the stream. If null is specified, the constructor creates a new boundary. If an empty string is specified, no content headers or boundaries are generated by this instance of the class.
Throws:
java.io.IOException - if the class instance is not initialized successfully.

IeMultipartOutputStream

public IeMultipartOutputStream(java.io.OutputStream out,
                               IeMultipartInputStream in)
                        throws java.io.IOException
Constructs an Info*Engine multipart output stream by wrapping a basic output stream and obtaining boundary and content type information from an Info*Engine servlet multipart input stream.

Parameters:
out - The basic output stream to be wrapped.
in - The servlet multipart input stream from which to obtain a boundary string and content type.
Throws:
java.io.IOException - if the class instance is not initialized successfully.
Method Detail

flush

public void flush()
           throws java.io.IOException
Flushes any output buffered on the output stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if buffered output is not flushed successfully.

close

public void close()
           throws java.io.IOException
Closes the output stream and releases resources allocated to it. If any output is buffered on the stream, it is flushed before closing the stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if buffered output is not flushed successfully.

setCharacterSet

public void setCharacterSet(java.lang.String encoding)
Sets the character set encoding to use when converting Info*Engine request objects to XML. UTF-8 is the default encoding.

Parameters:
encoding - The character set encoding name.

setForceEncoding

public void setForceEncoding(java.lang.String encoding)
Sets an encoding to use when writing text output. The encoding set with this method overrides the encoding derived from the "accept-language" parameter in the ServerData group.

Parameters:
encoding - The character set encoding name.

write

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

Overrides:
write in class java.io.OutputStream
Parameters:
b - The array of bytes to be written.
Throws:
java.io.IOException - if the array is not written successfully.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes a segment of an array of bytes to the output stream.

Overrides:
write in class java.io.OutputStream
Parameters:
b - The array of bytes to be written.
off - The index of the first byte to be written.
len - The number of bytes to be written, starting at off.
Throws:
java.io.IOException - if the segment is not written successfully.

write

public void write(int b)
           throws java.io.IOException
Writes a single byte to the output stream.

Specified by:
write in class java.io.OutputStream
Parameters:
b - The byte to be written.
Throws:
java.io.IOException - if the segment is not written successfully.

write

public void write(java.lang.String data,
                  java.lang.String name,
                  java.lang.String filename,
                  java.lang.String contentType)
           throws java.io.IOException
Writes one content object of a MIME multipart object to the output stream.

Parameters:
data - The string to be written to the output stream as the content data.
name - The name to be specified in the Content-Disposition header of the content object.
filename - The filename to be specified in the Content-Disposition header of the content object.
contentType - The MIME content type to be specified in the Content-Type header of the content object.
Throws:
java.io.IOException - if the content object is not written successfully.

write

public void write(java.lang.String name,
                  java.lang.String filename,
                  java.lang.String contentType)
           throws java.io.IOException
Writes a MIME content object header to the output stream.

Parameters:
name - The name to be specified in a Content-Disposition header.
filename - The filename to be specified in a Content-Disposition header.
contentType - The MIME content type to be specified a the Content-Type header.
Throws:
java.io.IOException - if the content object is not written successfully.

writeBlob

public void writeBlob(java.io.InputStream content,
                      java.lang.String name,
                      java.lang.String filename,
                      java.lang.String contentType)
               throws java.io.IOException
Writes one content object of a MIME multipart object to the output stream.

Parameters:
content - The input stream containing the bytes to be written to the output stream as the content data.
name - The name to be specified in the Content-Disposition header of the content object.
filename - The filename to be specified in the Content-Disposition header of the content object.
contentType - The MIME content type to be specified in the Content-Type header of the content object.
Throws:
java.io.IOException - if the content object is not written successfully.

writeBlob

public void writeBlob(java.io.InputStream content,
                      java.lang.String name,
                      java.lang.String filename,
                      java.lang.String contentType,
                      boolean flag)
               throws java.io.IOException
Deprecated. Use writeBlob() without the flag argument instead.

Writes one content object of a MIME multipart object to the output stream.

Parameters:
content - The input stream containing the bytes to be written to the output stream as the content data.
name - The name to be specified in the Content-Disposition header of the content object.
filename - The filename to be specified in the Content-Disposition header of the content object.
contentType - The MIME content type to be specified in the Content-Type header of the content object.
flag - Ignored.
Throws:
java.io.IOException - if the content object is not written successfully.

writeRequest

public void writeRequest(IeRequest request)
                  throws java.io.IOException
Writes an Info*Engine request object to the output stream. will use a default serialization type of application/java-serialized-object

Parameters:
request - The Info*Engine request object to be written.
Throws:
java.io.IOException - if the request object is not written successfully.

writeRequest

public void writeRequest(IeRequest request,
                         java.lang.String contentType)
                  throws java.io.IOException
Writes an Info*Engine request object to the output stream serializing according to contentType.

Parameters:
request - The Info*Engine request object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use application/java-serialized-object.
Throws:
java.io.IOException - if the request object is not written successfully.

writeRequest

public void writeRequest(IeRequest request,
                         java.lang.String contentType,
                         boolean exception)
                  throws java.io.IOException
Writes an Info*Engine request object to the output stream serializing according to contentType.

Parameters:
request - The Info*Engine request object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use application/java-serialized-object.
exception - States whether this request is the result of an exception or not. If true the MIME part for the request will be named "exception". If false the MIME part will be named "request".
Throws:
java.io.IOException - if the request object is not written successfully.

writeVdb

public void writeVdb(IeCollection vdb,
                     java.lang.String contentType)
              throws java.io.IOException
Writes an Info*Engine VDB object to the output stream serializing according to contentType.

Parameters:
vdb - The Info*Engine VDB object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use text/xml.
Throws:
java.io.IOException - if the request object is not written successfully.

writeVdb

public void writeVdb(IeCollection vdb,
                     java.lang.String contentType,
                     boolean exception)
              throws java.io.IOException
Writes an Info*Engine VDB object to the output stream serializing according to contentType.

Parameters:
vdb - The Info*Engine VDB object to be written.
contentType - The MIME content type to associate with the request. Currently accepts text/xml or application/java-serialized-object. If null, will use text/xml.
exception - States whether this VDB is the result of an exception or not. If true the MIME part for the VDB will be named "exception". If false the MIME part will be named "object".
Throws:
java.io.IOException - if the request object is not written successfully.

print

public void print(java.lang.String data)
           throws java.io.IOException
Prints a string to the output stream.

Parameters:
data - The string to be written.
Throws:
java.io.IOException - if the string is not written successfully.

println

public void println(java.lang.String data)
             throws java.io.IOException
Prints a string to the output stream with a CR/LF sequence appended.

Parameters:
data - The string to be written.
Throws:
java.io.IOException - if the string is not written successfully.

writeEOF

public void writeEOF()
              throws java.io.IOException
Writes a MIME multipart object termination boundary to the output stream.

Throws:
java.io.IOException - if the string is not written successfully.

eofWritten

public boolean eofWritten()
Tests whether an end of file indication (MIME termination boundary) has been written to the stream.

Returns:
true if end of file written.