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

Quick Search    Search Deep

com.lutris.mime
Class MultipartMimeInputStream  view MultipartMimeInputStream download MultipartMimeInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended bycom.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.


Field Summary
private  boolean atEOF
          EOF indicated to prevent skipping end marker twice.
private  boolean closed
          The stream is closed if true or not closed if false.
private  java.lang.String[] garbageHeaders
          Array of unparseable headers.
private  java.util.Hashtable headers
          Table of all parsed headers.
private  com.lutris.util.BMByteSearchStream inputSource
          Boyer-Moore streaming pattern searcher that represents the input source.
(package private)  boolean lastPart
          Boolean that indicates that this input stream was the last part of the total multipart input.
private static com.lutris.util.BMByteSearch newlinePattern
          Precomputed BM search pattern for "\n".
private  java.lang.String[] rawHeaders
          Array of raw, unparsed Mime headers.
private  byte[] readByte
          Byte to read into for single-byte read() operation.
private  com.lutris.util.BMByteSearch searchPattern
          Precomputed separator pattern search object.
 
Constructor Summary
protected MultipartMimeInputStream(com.lutris.util.BMByteSearchStream source, com.lutris.util.BMByteSearch sep)
          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.
private static char[] bytesToChars(byte[] buffer, int off, int len)
          Converts a byte array into a raw ASCII character array with characters in the range to ÿ by twos-complement signed-to-unsigned conversion.
private  void checkOpen()
          Used by routines that fail after closure to verify that the current stream is open.
 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.
private  int readAll(byte[] buffer)
          Reads into a byte array until the array is full, EOF is reached, or an I/O error occurs.
 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
 

Field Detail

inputSource

private com.lutris.util.BMByteSearchStream inputSource
Boyer-Moore streaming pattern searcher that represents the input source. It searches its InputStream, up to a specified pattern, returning the read data until the pattern is reached.


closed

private boolean closed
The stream is closed if true or not closed if false.


searchPattern

private com.lutris.util.BMByteSearch searchPattern
Precomputed separator pattern search object.


newlinePattern

private static com.lutris.util.BMByteSearch newlinePattern
Precomputed BM search pattern for "\n". This should only ever be computed once.


readByte

private byte[] readByte
Byte to read into for single-byte read() operation.


atEOF

private boolean atEOF
EOF indicated to prevent skipping end marker twice.


rawHeaders

private java.lang.String[] rawHeaders
Array of raw, unparsed Mime headers.


garbageHeaders

private java.lang.String[] garbageHeaders
Array of unparseable headers.


headers

private java.util.Hashtable headers
Table of all parsed headers.


lastPart

boolean lastPart
Boolean that indicates that this input stream was the last part of the total multipart input. This field is only to be accessed by the MultipartMimeInput object.

Constructor Detail

MultipartMimeInputStream

protected MultipartMimeInputStream(com.lutris.util.BMByteSearchStream source,
                                   com.lutris.util.BMByteSearch sep)
                            throws java.io.IOException,
                                   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.

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


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


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.


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.


available

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


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.


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.


getHeaders

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


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.


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.


readAll

private int readAll(byte[] buffer)
             throws java.io.IOException,
                    MimeEOFException
Reads into a byte array until the array is full, EOF is reached, or an I/O error occurs. This private method is intended only for reading individual lines of MIME headers. If the buffer is not long enough to hold an entire line from the input then the remainder bytes are skipped.


bytesToChars

private static final char[] bytesToChars(byte[] buffer,
                                         int off,
                                         int len)
Converts a byte array into a raw ASCII character array with characters in the range to ÿ by twos-complement signed-to-unsigned conversion.


checkOpen

private void checkOpen()
                throws java.io.IOException
Used by routines that fail after closure to verify that the current stream is open. If closed, this method throws an IOException to indicate an operation attempted on a closed stream.