Package org.apache.axiom.attachments
Class BoundaryDelimitedStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.axiom.attachments.BoundaryDelimitedStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BoundaryDelimitedStream extends FilterInputStream
This class takes the input stream and turns it multiple streams.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]boundaryprotected static intBOUNDARY_NOT_FOUNDField BOUNDARY_NOT_FOUND.protected static org.apache.commons.logging.LoglogTheLogthat this class should log all events to.protected intstreamNoField streamNo.-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBoundaryDelimitedStream(BoundaryDelimitedStream prev, int readbufsz)Constructor to create the next stream from the previous one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()protected intboundaryPosition(byte[] searchbuf, int start, int end)Read from the boundary delimited stream.voidclose()Closes the stream.protected voidfinalClose()Close the underlying stream and remove all references to it.BoundaryDelimitedStreamgetNextStream()Gets the next stream.protected BoundaryDelimitedStreamgetNextStream(int readbufsz)Gets the next stream.voidmark(int readlimit)mark the stream.booleanmarkSupported()markSupported return false;protected static intnewStreamNo()Signal that a new stream has been created.static voidprintarry(byte[] b, int start, int end)Method printarryintread()Read from the boundary delimited stream.intread(byte[] b)Read from the boundary delimited stream.intread(byte[] b, int off, int len)Read from the boundary delimited stream.voidreset()reset the stream.-
Methods inherited from class java.io.FilterInputStream
skip
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Field Detail
-
log
protected static org.apache.commons.logging.Log log
TheLogthat this class should log all events to.
-
boundary
protected byte[] boundary
-
BOUNDARY_NOT_FOUND
protected static final int BOUNDARY_NOT_FOUND
Field BOUNDARY_NOT_FOUND.- See Also:
- Constant Field Values
-
streamNo
protected int streamNo
Field streamNo.
-
-
Constructor Detail
-
BoundaryDelimitedStream
protected BoundaryDelimitedStream(BoundaryDelimitedStream prev, int readbufsz) throws IOException
Constructor to create the next stream from the previous one.- Parameters:
prev- the previous streamreadbufsz- how many bytes to make the read buffer- Throws:
IOException- if there was a problem reading data fromprev
-
-
Method Detail
-
newStreamNo
protected static int newStreamNo()
Signal that a new stream has been created.
-
getNextStream
public BoundaryDelimitedStream getNextStream() throws IOException
Gets the next stream. From the previous using the same buffer size to read.- Returns:
- the boundary delmited stream, null if there are no more streams.
- Throws:
IOException- if there was an error loading the data for the next stream
-
getNextStream
protected BoundaryDelimitedStream getNextStream(int readbufsz) throws IOException
Gets the next stream. From the previous using new buffer reading size.- Parameters:
readbufsz-- Returns:
- the boundary delmited stream, null if there are no more streams.
- Throws:
IOException- if there was an error loading the data for the next stream
-
read
public int read(byte[] b, int off, int len) throws IOExceptionRead from the boundary delimited stream.- Overrides:
readin classFilterInputStream- Parameters:
b- is the array to read into.off- is the offsetlen-- Returns:
- the number of bytes read. -1 if endof stream.
- Throws:
IOException
-
read
public int read(byte[] b) throws IOExceptionRead from the boundary delimited stream.- Overrides:
readin classFilterInputStream- Parameters:
b- is the array to read into. Read as much as possible into the size of this array.- Returns:
- the number of bytes read. -1 if endof stream.
- Throws:
IOException
-
read
public int read() throws IOExceptionRead from the boundary delimited stream.- Overrides:
readin classFilterInputStream- Returns:
- The byte read, or -1 if endof stream.
- Throws:
IOException
-
close
public void close() throws IOExceptionCloses the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException
-
mark
public void mark(int readlimit)
mark the stream. This is not supported.- Overrides:
markin classFilterInputStream- Parameters:
readlimit-
-
reset
public void reset() throws IOExceptionreset the stream. This is not supported.- Overrides:
resetin classFilterInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()
markSupported return false;- Overrides:
markSupportedin classFilterInputStream
-
available
public int available() throws IOException- Overrides:
availablein classFilterInputStream- Throws:
IOException
-
boundaryPosition
protected int boundaryPosition(byte[] searchbuf, int start, int end) throws IOExceptionRead from the boundary delimited stream.- Parameters:
searchbuf- buffer to read fromstart- starting indexend- ending index- Returns:
- The position of the boundary. Detects the end of the source stream.
- Throws:
IOException- if there was an error manipulating the underlying stream
-
finalClose
protected void finalClose() throws IOExceptionClose the underlying stream and remove all references to it.- Throws:
IOException- if the stream could not be closed
-
printarry
public static void printarry(byte[] b, int start, int end)Method printarry- Parameters:
b-start-end-
-
-