org.talika.tarsis.filters.upload
Class MultipartInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.talika.tarsis.filters.upload.MultipartInputStream
All Implemented Interfaces:
java.io.Closeable

public final class MultipartInputStream
extends java.io.FilterInputStream

Defines a specialiced InputStream to process a multipart stream.

It provides two specialiced methods, readLine and readData.

Version:
$Revision: 127 $
Author:
Jose M. Palomar

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
MultipartInputStream(java.io.InputStream in, java.lang.String boundary, java.lang.String encoding)
          Creates a new MultipartInputStream.
 
Method Summary
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] buffer, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 int readData(byte[] buffer, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 java.lang.String readLine()
          Read a line of text.
 java.lang.String readLine(java.lang.String encoding)
          Read a line of text using given encoding.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartInputStream

public MultipartInputStream(java.io.InputStream in,
                            java.lang.String boundary,
                            java.lang.String encoding)
                     throws java.io.IOException
Creates a new MultipartInputStream.

Parameters:
in - InputStream the input stream from which bytes will be read.
boundary - String boundary of multipart.
encoding - String encoding of multipart.
Throws:
java.io.IOException - if an I/O error occurs.
Method Detail

read

public int read(byte[] buffer,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

Overrides:
read in class java.io.FilterInputStream
Parameters:
buffer - byte[] the buffer into which the data is read.
off - int the start offset in array b at which the data is written.
len - int the maximum number of bytes to read.
Returns:
int the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read()
         throws java.io.IOException
Reads the next byte of data from the 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.

Overrides:
read in class java.io.FilterInputStream
Returns:
int the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Read a line of text. A line is considered to be terminated by a carriage return ('\r') followed immediately by a linefeed ('\n').

Returns:
String A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

readLine

public java.lang.String readLine(java.lang.String encoding)
                          throws java.io.IOException
Read a line of text using given encoding. A line is considered to be terminated by a carriage return ('\r') followed immediately by a linefeed ('\n').

Parameters:
encoding - String charset encoding.
Returns:
String A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.

readData

public int readData(byte[] buffer,
                    int off,
                    int len)
             throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.

Parameters:
buffer - byte[] the buffer into which the data is read.
off - int the start offset in array b at which the data is written.
len - int the maximum number of bytes to read.
Returns:
int the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - if an I/O error occurs.


Copyright © 2002-2012 Talika Open Source Group. All Rights Reserved.