com.infoengine.object
Class IeMultipartInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended bycom.infoengine.object.IeInputStream
          extended bycom.infoengine.object.IeMultipartInputStream
Direct Known Subclasses:
IeEncodedInputStream, ServletMultipartInputStream, SOAPAttachmentInputStream

public class IeMultipartInputStream
extends IeInputStream


Field Summary
protected  String boundary
           
(package private) static String BOUNDARY_PARAM
           
private  String characterEncoding
           
private  int contentLength
           
protected  String contentType
           
private  ContentHeader currentContentHeader
           
static String DEFAULT_BOUNDARY
           
static String DEFAULT_EOF
           
static String DEFAULT_EOL
           
protected  boolean eofRead
           
private  boolean firstBoundary
           
(package private) static String MULTIPART
           
(package private) static String MULTIPART_FORM_DATA
           
private  boolean oneContent
           
private  Hashtable parameters
           
protected  Vector pushedBack
           
protected  String requestContentType
           
private  Vector xGroups
           
 
Fields inherited from class com.infoengine.object.IeInputStream
inputBuffer, inputBufferCursor, inputBufferLimit, inputStream
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
IeMultipartInputStream()
          Use this constructor with setInputStream.
IeMultipartInputStream(InputStream is)
          This constructor will block until the mime header can be read off the input stream.
IeMultipartInputStream(InputStream is, String contentType, String name, String filename)
          This constructor creates a multipart stream from a non-multipart input stream.
IeMultipartInputStream(javax.servlet.ServletRequest request)
          This constructor sets the internal input stream to the request's input stream.
 
Method Summary
 boolean eofRead()
           
 String getBoundary()
          Returns the MIME boundary string that separates the content objects read from the stream.
 ContentHeader getContentHeader()
          Returns the last MIME content header object read from the input stream.
 int getContentLength()
           
 String getContentType()
          Returns the MIME content type associated with the multipart input stream as a whole.
 String getParameter(String name)
          Returns the value of a named parameter.
 Enumeration getParameterNames()
          Returns the names of all parameters.
 Vector getParameterValues(String name)
          Returns the values of a named parameter.
 String getRequestContentType()
          Returns the MIME content type associated with the incoming request.
 Enumeration getXGroups()
          returns an Enumeration of IeGroup objects found in the incoming MIME stream.
 boolean pushBackCalled()
          Returns an indication of whether any MIME content headers have ever been pushed onto the internal stack.
 void pushBackHeader(ContentHeader header)
          Pushes a MIME content header object onto an internal stack.
 byte[] readBlob()
          Reads the next BLOB on the input stream and returns it as a byte array.
 void readBlob(OutputStream os)
          Reads the next BLOB on the input stream and writes it to an output stream.
 ContentHeader readBlobInfo()
          Reads the next MIME content header from the input stream.
 String readBoundary()
          Reads the next boundary line from the MIME input stream.
 ContentHeader readHeader()
           
 int readLine(byte[] bbuf)
          Reads the next line from the MIME input stream into a byte array.
 int readLine(byte[] bbuf, int start, int max)
          Reads the next line from the MIME input stream into a byte array, beginning at a specific index of the array and continuing until the end of the line is detected or a maximum number of bytes is read.
 IeRequest readRequest()
          Reads the next content object from the input stream and parses it as an Info*Engine request object.
 String readText()
          Reads the next text object on the input stream and returns it as a String.
 void readText(OutputStream os)
          Reads the next text object on the input stream and writes it to an output stream.
 IeCollection readVdb()
          Reads the next content object from the input stream and parses it as an Info*Engine VDB object.
private  void readXVDB()
          called to deal with POSTED MIME parts with content-type of application/x-infoengine-collection.
 void streamBlobs(OutputStream os)
          Copies every BLOB on the input stream to an output stream.
 
Methods inherited from class com.infoengine.object.IeInputStream
available, close, getInputStream, mark, markSupported, read, read, read, readLine, readLine, reset, setInputStream, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOUNDARY_PARAM

static final String BOUNDARY_PARAM
See Also:
Constant Field Values

MULTIPART

static final String MULTIPART
See Also:
Constant Field Values

MULTIPART_FORM_DATA

static final String MULTIPART_FORM_DATA
See Also:
Constant Field Values

DEFAULT_BOUNDARY

public static final String DEFAULT_BOUNDARY
See Also:
Constant Field Values

DEFAULT_EOF

public static final String DEFAULT_EOF
See Also:
Constant Field Values

DEFAULT_EOL

public static final String DEFAULT_EOL
See Also:
Constant Field Values

contentType

protected String contentType

requestContentType

protected String requestContentType

boundary

protected String boundary

eofRead

protected boolean eofRead

oneContent

private boolean oneContent

currentContentHeader

private ContentHeader currentContentHeader

pushedBack

protected Vector pushedBack

firstBoundary

private boolean firstBoundary

parameters

private Hashtable parameters

xGroups

private Vector xGroups

characterEncoding

private String characterEncoding

contentLength

private int contentLength
Constructor Detail

IeMultipartInputStream

public IeMultipartInputStream()
Use this constructor with setInputStream. This allows you to defer blocking on input until the input stream is ready.


IeMultipartInputStream

public IeMultipartInputStream(javax.servlet.ServletRequest request)
                       throws IOException
This constructor sets the internal input stream to the request's input stream. It uses the request to get the content type. If multipart the input stream is positioned at the first content object that specifies a file name (the first BLOB).

Parameters:
request - A servlet request object from which to obtain an input stream containing a MIME multipart object.

IeMultipartInputStream

public IeMultipartInputStream(InputStream is)
                       throws IOException
This constructor will block until the mime header can be read off the input stream. From the mime header it gets the content type and length. Use the default constructor and setInputStream if you want a finer control.

Parameters:
is - The input stream containing a MIME multipart object.

IeMultipartInputStream

public IeMultipartInputStream(InputStream is,
                              String contentType,
                              String name,
                              String filename)
                       throws IOException
This constructor creates a multipart stream from a non-multipart input stream. Use this constructor to handle a simple input stream, such as a file input stream or a byte array input stream, as if it is an Info*Engine multipart input stream containing exactly one content object.

Parameters:
is - The non-multipart input stream.
contentType - The MIME content type to be associated with the stream.
name - The form variable name to be associated with the stream.
filename - The file name to be associated with the stream.
Method Detail

readXVDB

private void readXVDB()
               throws IOException
called to deal with POSTED MIME parts with content-type of application/x-infoengine-collection. these types of parts are/were sent as form data from old JSPs via scriptlets containing code like: ie.beginRequestWithParameters ( "EchoRequest.html" ); ie.sendCollection (); Groups MAY be available when the stream has been created with a ServletRequest object and one or more of these body parts if found within the MIME stream. The groups can be retrieved via the getXGroups() method.

Throws:
IOException

getXGroups

public Enumeration getXGroups()
returns an Enumeration of IeGroup objects found in the incoming MIME stream.


getParameter

public String getParameter(String name)
Returns the value of a named parameter. Use this method only when it is known that a parameter is single-valued. Use getParameterValues when a parameter can be multi-valued.

Parameters are available only when an IeMultipartInputStream is derived from a ServletRequest object (see the appropriate constructor above). Parameters are form variables submitted in an HTTP POST request with the MIME type multipart/form-data.

Parameters:
name - The name of the parameter.
Returns:
The value of the named parameter, or null if the parameter is not found in the input stream.

getParameterValues

public Vector getParameterValues(String name)
Returns the values of a named parameter.

Parameters are available only when an IeMultipartInputStream is derived from a ServletRequest object (see the appropriate constructor above). Parameters are form variables submitted in an HTTP POST request with the MIME type multipart/form-data.

Parameters:
name - The name of the parameter.
Returns:
The values of the named parameter, or null if the parameter is not found in the input stream.

getParameterNames

public Enumeration getParameterNames()
Returns the names of all parameters.

Parameters are available only when an IeMultipartInputStream is derived from a ServletRequest object (see the appropriate constructor above). Parameters are form variables submitted in an HTTP POST request with the MIME type multipart/form-data.

Returns:
The names of all parameters obtained from the input stream.

getContentHeader

public ContentHeader getContentHeader()
Returns the last MIME content header object read from the input stream.

Returns:
The last content header object read.

readRequest

public IeRequest readRequest()
                      throws IOException,
                             IEException
Reads the next content object from the input stream and parses it as an Info*Engine request object.

Returns:
The Info*Engine request object read from the input stream.
Throws:
IOException - if the next object on the input stream is not an Info*Engine request object.
IEException

readVdb

public IeCollection readVdb()
                     throws IOException,
                            IEException
Reads the next content object from the input stream and parses it as an Info*Engine VDB object.

Returns:
The Info*Engine VDB object read from the input stream.
Throws:
IOException - if the next object on the input stream is not an Info*Engine VDB object.
IEException

readBlob

public void readBlob(OutputStream os)
              throws IOException
Reads the next BLOB on the input stream and writes it to an output stream. Before calling this method, you must call readBlobInfo() to read the MIME header that precedes and describes the BLOB data.

Parameters:
os - The output stream on which to write the BLOB.
Throws:
IOException - if the input stream can not be read successfully.

readBlob

public byte[] readBlob()
                throws IOException
Reads the next BLOB on the input stream and returns it as a byte array. Before calling this method, you must call readBlobInfo() to read the MIME header that precedes and describes the BLOB data.

Returns:
The byte array containing the BLOB.
Throws:
IOException - if the input stream can not be read successfully.

readText

public void readText(OutputStream os)
              throws IOException
Reads the next text object on the input stream and writes it to an output stream. Before calling this method, you must call readBlobInfo() to read the MIME header that precedes and describes the text object.

Parameters:
os - The output stream on which to write the text object.
Throws:
IOException - if the input stream can not be read successfully.

readText

public String readText()
                throws IOException
Reads the next text object on the input stream and returns it as a String. Before calling this method, you must call readBlobInfo() to read the MIME header that precedes and describes the text object.

Returns:
The String containing the test object.
Throws:
IOException - if the input stream can not be read successfully.

readBlobInfo

public ContentHeader readBlobInfo()
                           throws IOException
Reads the next MIME content header from the input stream. You must call this method before calling the readBlob() or readText() methods.

Returns:
The MIME content header object.
Throws:
IOException - if the input stream can not be read successfully.

streamBlobs

public void streamBlobs(OutputStream os)
                 throws IOException
Copies every BLOB on the input stream to an output stream. When this method returns, the input stream is positioned at its end.

Parameters:
os - The output stream on which to write all of the BLOB's read from the input stream.
Throws:
IOException - if the input stream can not be read or the output stream can not be written successfully.

readBoundary

public String readBoundary()
                    throws IOException
Reads the next boundary line from the MIME input stream.

Returns:
The boundary line read.
Throws:
IOException - if the input stream can not be read successfully.

readLine

public int readLine(byte[] bbuf)
             throws IOException
Reads the next line from the MIME input stream into a byte array. If a complete line is read, the array will contain the text of the line as well as the end of line character(s). If the next line is longer than the supplied byte array, the byte array is filled, and the method will need to be called again to read the remainder of the line.

Parameters:
bbuf - The byte array in which to store the bytes read from the input stream.
Returns:
The number of bytes read into the array.
Throws:
IOException - if the input stream can not be read successfully.

readLine

public int readLine(byte[] bbuf,
                    int start,
                    int max)
             throws IOException
Reads the next line from the MIME input stream into a byte array, beginning at a specific index of the array and continuing until the end of the line is detected or a maximum number of bytes is read. If a complete line is read, the array will contain the text of the line as well as the end of line character(s). If the next line is longer than the maximum number of bytes specified, the method will need to be called again to read the remainder of the line.

Parameters:
bbuf - The byte array in which to store the bytes read from the input stream.
start - The index of the array in which to store the first byte.
max - The maximum number of bytes to read.
Returns:
The number of bytes read into the array.
Throws:
IOException - if the input stream can not be read successfully.

getRequestContentType

public String getRequestContentType()
Returns the MIME content type associated with the incoming request. This method can be called following a call to readRequest to get the content type of the incoming request object. (typically either 'text/xml' or 'application/java-serialized-object'

Returns:
The MIME content type of request.

getContentType

public String getContentType()
Returns the MIME content type associated with the multipart input stream as a whole.

Returns:
The MIME content type of the stream.

getBoundary

public String getBoundary()
Returns the MIME boundary string that separates the content objects read from the stream.

Returns:
The MIME boundary string.

pushBackHeader

public void pushBackHeader(ContentHeader header)
Pushes a MIME content header object onto an internal stack. This header will be returned in the next call to readBlobInfo(). This allows an application to scan the input stream for a particular kind of content object, then push its MIME header back onto the stream.

Parameters:
header - The content header to be pushed onto the stack.

pushBackCalled

public boolean pushBackCalled()
Returns an indication of whether any MIME content headers have ever been pushed onto the internal stack.

Returns:
true if content headers have been pushed onto the stack, false if the stack has never been used.

readHeader

public ContentHeader readHeader()
                         throws IOException
Throws:
IOException

getContentLength

public int getContentLength()

eofRead

public boolean eofRead()