EAF 7.4 Implementation

com.lutris.mime
Class MultipartMimeInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.lutris.mime.MultipartMimeInputStream
All Implemented Interfaces:
java.io.Closeable

public class MultipartMimeInputStream
extends java.io.InputStream

Presents the current section of a multipart MIME stream as a distinct InputStream object for which the end of the section is the end of the stream. MIME headers for the current section are extracted, parsed, and made available via the getMimeHeaders() method. The stream itself begins at the first byte following the Mime header section. Closing an instance of MultipartMimeInputStream causes it to skip data on the underlying input stream until the next section is found, or end-of-input is reached.


Constructor Summary
protected MultipartMimeInputStream(BMByteSearchStream source, BMByteSearch sep)
          Creates a MultipartFormStream object from the given pattern search stream object, separator, and end of line pattern.
protected MultipartMimeInputStream(BMByteSearchStream source, BMByteSearch sep, java.lang.String encoding)
          Creates a MultipartFormStream object from the given pattern search stream object, separator, and end of line pattern.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from this stream without blocking.
 void close()
          Skips all remaining bytes on this stream and closes it.
 java.lang.String[] getGarbageHeaders()
          Returns an array of all Mime header lines that could not be parsed in the normal "name: value" fashion.
 MimeHeader getHeader(java.lang.String headerName)
          Returns a single MimeHeader object associated with a given Mime header name.
 MimeHeader[] getHeaders(java.lang.String headerName)
          Returns a array of type MimeHeader containing all values associated with a given Mime header name.
 java.lang.String[] getRawHeaders()
          Returns an array of String containing each Mime header as it was read from the header of this section.
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] buffer)
          Reads up to buffer.length bytes of data from this input stream into an array of bytes.
 int read(byte[] buffer, int offset, int length)
          Reads length bytes of data from this input stream into an array of bytes.
 long skip(long num)
          Skips over and discards n bytes of data from this input stream.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartMimeInputStream

protected MultipartMimeInputStream(BMByteSearchStream source,
                                   BMByteSearch sep)
                            throws java.io.IOException,
                                   com.lutris.mime.MimeEOFException
Creates a MultipartFormStream object from the given pattern search stream object, separator, and end of line pattern. This constructor may only be called internally from within MultipartMimeInput or its derived subclasses. Other packages never create instances of this class directly.

Parameters:
source - Input stream that can perform a pattern serarch on the raw input stream.
sep - Separator pattern.
Throws:
java.io.IOException - If an I/O error occurs.
MimeEOFException - If at EOF and the current section does not exist.

MultipartMimeInputStream

protected MultipartMimeInputStream(BMByteSearchStream source,
                                   BMByteSearch sep,
                                   java.lang.String encoding)
                            throws java.io.IOException,
                                   com.lutris.mime.MimeEOFException
Creates a MultipartFormStream object from the given pattern search stream object, separator, and end of line pattern. This constructor may only be called internally from within MultipartMimeInput or its derived subclasses. Other packages never create instances of this class directly.

Parameters:
source - Input stream that can perform a pattern serarch on the raw input stream.
sep - Separator pattern.
encoding - String encoding to apply.
Throws:
java.io.IOException - If an I/O error occurs.
MimeEOFException - If at EOF and the current section does not exist.
Method Detail

read

public int read()
         throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown

Specified by:
read in class java.io.InputStream
Returns:
The next byte of data, or -1 if the end of stream is reached.
Throws:
java.io.IOException - If an I/O error occurs.

read

public int read(byte[] buffer)
         throws java.io.IOException
Reads up to buffer.length bytes of data from this input stream into an array of bytes. This method blocks until some input is available

Overrides:
read in class java.io.InputStream
Parameters:
buffer - The buffer into which data are read.
Returns:
The number of bytes actually read, or -1 if there are no more bytes because the end of stream has been reached.
Throws:
java.io.IOException - If an I/O error occurs.

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Overrides:
read in class java.io.InputStream
Parameters:
buffer - The buffer into which data are read.
offset - The start offset of the data.
length - The maximum number of bytes read.
Returns:
The total number of bytes read into the buffer, or -1 if there are no more bytes because the end of stream has been reached.
Throws:
java.io.IOException - If an I/O error occurs.

skip

public long skip(long num)
          throws java.io.IOException
Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Overrides:
skip in class java.io.InputStream
Parameters:
num - The number of bytes to be skipped.
Returns:
The actual number of bytes skipped.
Throws:
java.io.IOException - If an I/O error occurs.

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read from this stream without blocking.

Overrides:
available in class java.io.InputStream
Returns:
The number of bytes that can be read from this stream without blocking.
Throws:
java.io.IOException - If an I/O error occurs.

close

public void close()
           throws java.io.IOException
Skips all remaining bytes on this stream and closes it. Further operations on this stream, other than close() will cause an IOException to be thrown.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - If an I/O error occurs.

getHeader

public MimeHeader getHeader(java.lang.String headerName)
Returns a single MimeHeader object associated with a given Mime header name. If the selected header name is associated with more than one value, then the last instance received from the input stream is returned.

Parameters:
headerName - The name of the Mime header to return.
Returns:
The value of the header, or null if not found.

getHeaders

public MimeHeader[] getHeaders(java.lang.String headerName)
Returns a array of type MimeHeader containing all values associated with a given Mime header name.

Parameters:
headerName - The name of the Mime header to return.
Returns:
All values associated with the header, or null if not found.

getRawHeaders

public java.lang.String[] getRawHeaders()
Returns an array of String containing each Mime header as it was read from the header of this section. All whitespace and punctuation is left intact.

Returns:
Array of raw Mime headers.

getGarbageHeaders

public java.lang.String[] getGarbageHeaders()
Returns an array of all Mime header lines that could not be parsed in the normal "name: value" fashion.

Returns:
Array of raw Mime headers.

EAF 7.4 Implementation