com.infoengine.object
Class IeMultipartOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycom.infoengine.object.IeMultipartOutputStream
Direct Known Subclasses:
SOAPAttachmentOutputStream

public class IeMultipartOutputStream
extends OutputStream

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


Nested Class Summary
(package private)  class IeMultipartOutputStream.BitBucket
           
 
Field Summary
protected  String boundary
           
private static String CONTENT_TYPE
           
protected  int contentLength
           
private static byte[] CRLF
           
private static byte[] DASH2
           
private static String DISPOSITION
           
protected  String encoding
           
protected  boolean eof
           
private static String FILENAME
           
private static String FILENAME_STAR
           
protected  String forceEncoding
           
private static String NAME
           
protected  OutputStream out
           
private static String RESOURCE
           
private static long seqNum
           
 
Constructor Summary
IeMultipartOutputStream(OutputStream out)
          Constructs an Info*Engine multipart output stream by wrapping a basic output stream.
IeMultipartOutputStream(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(OutputStream out, 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.
protected  void initialize(String contentType, int contentLength, String boundary)
           
protected  void initialize(String contentType, String boundary)
           
private  boolean isUsASCII(String s)
           
 void print(String data)
          Prints a string to the output stream.
 void println(String data)
          Prints a string to the output stream with a CR/LF sequence appended.
 void setCharacterSet(String encoding)
          Sets the character set encoding to use when converting Info*Engine request objects to XML.
 void setForceEncoding(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(String name, String filename, String contentType)
          Writes a MIME content object header to the output stream.
 void write(String data, String name, String filename, String contentType)
          Writes one content object of a MIME multipart object to the output stream.
 void writeBlob(InputStream content, String name, String filename, String contentType)
          Writes one content object of a MIME multipart object to the output stream.
 void writeBlob(InputStream content, String name, String filename, String contentType, boolean flag)
          Deprecated. Use writeBlob() without the flag argument instead.
private  void writeContentType(String contentType)
           
private  void writeDisposition(String name, String filename)
           
 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, String contentType)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeRequest(IeRequest request, String contentType, boolean exception)
          Writes an Info*Engine request object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, String contentType)
          Writes an Info*Engine VDB object to the output stream serializing according to contentType.
 void writeVdb(IeCollection vdb, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected OutputStream out

encoding

protected String encoding

forceEncoding

protected String forceEncoding

eof

protected boolean eof

contentLength

protected int contentLength

boundary

protected String boundary

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

DISPOSITION

private static final String DISPOSITION
See Also:
Constant Field Values

NAME

private static final String NAME
See Also:
Constant Field Values

FILENAME

private static final String FILENAME
See Also:
Constant Field Values

FILENAME_STAR

private static final String FILENAME_STAR
See Also:
Constant Field Values

CONTENT_TYPE

private static final String CONTENT_TYPE
See Also:
Constant Field Values

CRLF

private static final byte[] CRLF

DASH2

private static final byte[] DASH2

seqNum

private static long seqNum
Constructor Detail

IeMultipartOutputStream

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

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

IeMultipartOutputStream

public IeMultipartOutputStream(OutputStream out,
                               String boundary)
                        throws 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:
IOException - if the class instance is not initialized successfully.

IeMultipartOutputStream

public IeMultipartOutputStream(OutputStream out,
                               IeMultipartInputStream in)
                        throws 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:
IOException - if the class instance is not initialized successfully.
Method Detail

flush

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

Throws:
IOException - if buffered output is not flushed successfully.

close

public void close()
           throws 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.

Throws:
IOException - if buffered output is not flushed successfully.

setCharacterSet

public void setCharacterSet(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(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 IOException
Writes an array of bytes to the output stream.

Parameters:
b - The array of bytes to be written.
Throws:
IOException - if the array is not written successfully.

write

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

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:
IOException - if the segment is not written successfully.

write

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

Parameters:
b - The byte to be written.
Throws:
IOException - if the segment is not written successfully.

write

public void write(String data,
                  String name,
                  String filename,
                  String contentType)
           throws 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:
IOException - if the content object is not written successfully.

write

public void write(String name,
                  String filename,
                  String contentType)
           throws 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:
IOException - if the content object is not written successfully.

writeBlob

public void writeBlob(InputStream content,
                      String name,
                      String filename,
                      String contentType)
               throws 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:
IOException - if the content object is not written successfully.

writeBlob

public void writeBlob(InputStream content,
                      String name,
                      String filename,
                      String contentType,
                      boolean flag)
               throws 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:
IOException - if the content object is not written successfully.

writeRequest

public void writeRequest(IeRequest request)
                  throws 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:
IOException - if the request object is not written successfully.

writeRequest

public void writeRequest(IeRequest request,
                         String contentType)
                  throws 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:
IOException - if the request object is not written successfully.

writeRequest

public void writeRequest(IeRequest request,
                         String contentType,
                         boolean exception)
                  throws 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:
IOException - if the request object is not written successfully.

writeVdb

public void writeVdb(IeCollection vdb,
                     String contentType)
              throws 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:
IOException - if the request object is not written successfully.

writeVdb

public void writeVdb(IeCollection vdb,
                     String contentType,
                     boolean exception)
              throws 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:
IOException - if the request object is not written successfully.

print

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

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

println

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

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

writeEOF

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

Throws:
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.

initialize

protected void initialize(String contentType,
                          int contentLength,
                          String boundary)
                   throws IOException
Throws:
IOException

initialize

protected void initialize(String contentType,
                          String boundary)
                   throws IOException
Throws:
IOException

writeDisposition

private void writeDisposition(String name,
                              String filename)
                       throws IOException
Throws:
IOException

isUsASCII

private boolean isUsASCII(String s)

writeContentType

private void writeContentType(String contentType)
                       throws IOException
Throws:
IOException