Class MPInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,wt.util.MPInputStreamIfc
The only required steps are to instantiate a new MPInputStream (passing in the HTTPRequest's input stream and CGI_MULTIPART_BOUNDARY), and to call MP's hasMoreObjectBodies method. Provided the the instantiation succeeds and the return value of the hasMoreObjectBodies method call is true, the business class is free to proceed with reading of the first object body.
Upon receipt of a negative one from a read request, said object body is finished. The return value of another call to hasMoreObjectBodies will indicate if another object body is available for reading.
Note that this input stream filter reads the object body data as bytes, and
thus does not impinge any format nor conversion upon the data therein. Thus
if the object body data is, for example, base64 encoded, the resultant reads
of the business class will get base64 encoded data. It is in this way, that
this filter can operate independant of the data enclosed in the object body.
It is therefore incumbant on the business class to perform any post
processing of the data that may be necessary.
Supported API: true
Extendable: false
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionMPInputStream(InputStream in, String boundary) Creates a new MPInputStream initialized with the specified input stream and object body boundary
Supported API: true -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes that can be read without blocking.booleanPublic checker for specific Object Body Header.Public accessor to specific Object Body Header.Public accessor to Object Body Headers and values.get the character encoding set bysetEncodingmethod.getEncoding(String encoding) Deprecated.booleanSetup read of next object body if one is available.final intread()Reads a byte of data.final intread(byte[] b) Reads up tob.lengthbytes of data from this input stream into an array of bytes.final intread(byte[] b, int off, int len) Reads up tolenbytes of data from this MP input stream into an array of bytes.Reads the remainder of the current body part into a string.voidsetEncoding(String encoding) Set character encoding to be returned bygetEncodingmethod.longskip(long n) Skips bytes of input.Methods inherited from class java.io.FilterInputStream
close, mark, markSupported, resetMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
MPInputStream
Creates a new MPInputStream initialized with the specified input stream and object body boundary
Supported API: true- Parameters:
in- the input streamboundary- the encapsulation boundary string
-
-
Method Details
-
setEncoding
Set character encoding to be returned bygetEncodingmethod. Useful if the creator of aMPInputStreamwant to communicate a known character encoding to a body part processing method.
Supported API: true- Specified by:
setEncodingin interfacewt.util.MPInputStreamIfc- Parameters:
encoding- the character encoding
-
getEncoding
Deprecated.
Supported API: trueget the character encoding set bysetEncodingmethod. Returns null if not encoding has been set for thisMPInputStream.- Returns:
- encoding the character encoding
-
getEncoding
get the character encoding set bysetEncodingmethod. Returns null if not encoding has been set for thisMPInputStream.
Supported API: true- Specified by:
getEncodingin interfacewt.util.MPInputStreamIfc- Returns:
- encoding the character encoding
-
hasMoreObjectBodies
Setup read of next object body if one is available. Accomplished by checking that the encapsulation boundary at the top of the header is what we expect, generate a hashtable of the object body headers for later retrieval, and set the stream to the top of the body data for subsequent reads.
Supported API: true- Specified by:
hasMoreObjectBodiesin interfacewt.util.MPInputStreamIfc- Throws:
IOException- is thrown if error on reading object body header(s) or encapsulation boundary doesn't match that which was passed into the constructor, of read from the boundary object body header.Note: this method must be called and a value of true returned prior to getBodyHeaders() and/or getBodyHeader(String s) calls.
-
getBodyHeaders
Public accessor to Object Body Headers and values.
Supported API: true- Specified by:
getBodyHeadersin interfacewt.util.MPInputStreamIfc
-
getBodyHeader
Public accessor to specific Object Body Header.
Supported API: true- Specified by:
getBodyHeaderin interfacewt.util.MPInputStreamIfc- Parameters:
s- string key for which to get value.
-
containsBodyHeader
Public checker for specific Object Body Header.
Supported API: true- Specified by:
containsBodyHeaderin interfacewt.util.MPInputStreamIfc- Parameters:
s- string key for which to get value.
-
read
Reads a byte of data. The method will block if no input is available.
Supported API: true- Specified by:
readin interfacewt.util.MPInputStreamIfc- Overrides:
readin classFilterInputStream- Returns:
- the byte read, or -1 if the end of the stream is reached.
- Throws:
IOException- If an I/O error has occurred. We are overriding this to return 0 bytes for now. Should just call read (byte[], 0, 1)...maybe?
-
read
Reads up tob.lengthbytes of data from this input stream into an array of bytes.The
readmethod ofMPInputStreamcalls thereadmethod of three arguments with the argumentsb,0, andb.length.
Supported API: true- Specified by:
readin interfacewt.util.MPInputStreamIfc- Overrides:
readin classFilterInputStream- Parameters:
b- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1is there is no more data because the end of the stream has been reached. - Throws:
IOException- if an I/O error occurs.- Since:
- JDK1.0
- See Also:
-
read
Reads up tolenbytes of data from this MP input stream into an array of bytes. This method blocks until some input is available.This
readmethod ofMPInputStreamreads bytes out of an internal buffer.
Supported API: true- Specified by:
readin interfacewt.util.MPInputStreamIfc- Overrides:
readin classFilterInputStream- Parameters:
b- the buffer into which the data is read.off- the start offset of the data.len- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of the object body has been reached. - Throws:
IOException- if an I/O error occurs.
-
skip
Skips bytes of input.
Supported API: true- Specified by:
skipin interfacewt.util.MPInputStreamIfc- Overrides:
skipin classFilterInputStream- Parameters:
n- bytes to be skipped- Returns:
- actual number of bytes skipped
- Throws:
IOException- If an I/O error has occurred.
-
available
public int available()Returns the number of bytes that can be read without blocking. Returns number of bytes body bytes already read into local buffer.
Supported API: true- Specified by:
availablein interfacewt.util.MPInputStreamIfc- Overrides:
availablein classFilterInputStream- Returns:
- number of bytes available
-
readString
Reads the remainder of the current body part into a string.
Supported API: true- Specified by:
readStringin interfacewt.util.MPInputStreamIfc- Returns:
- String read using the encoding set for this stream
- Throws:
IOException- if an I/O error occurs.
-
Supported API: true