org.jboss.soa.esb.actions.soap.attachment
Class BoundaryDelimitedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by org.jboss.soa.esb.actions.soap.attachment.BoundaryDelimitedInputStream
All Implemented Interfaces:
java.io.Closeable

public class BoundaryDelimitedInputStream
extends java.io.FilterInputStream

BoundaryDelimitedInputStream encapsulates a stream that is sepearated into different sections by a common boundary, such as a MIME multipart message. The full stream is referred to as the outer stream. Each boundary separated section in the outer stream is referred to as an inner stream. All read() methods will start from the first inner stream, returning -1 when a boundary is reached. Subsequent calls will then advance to the next stream, skipping the boundary.

Author:
Jason T. Greene

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
BoundaryDelimitedInputStream(java.io.InputStream in, byte[] boundary)
          Constructs a BoundaryDelimitedInputStream using the passed InputStream as the source for the outer stream.
 
Method Summary
 int available()
          This method will always return 0 because this input stream must always read ahead to determine the location of the boundary.
 void close()
          Close this input stream, and its source input stream.
 boolean isOuterStreamClosed()
          Returns whether the outer stream is closed.
 boolean markSupported()
          Returns false.
 void printLeftOvers()
           
 int read()
          Reads a single byte from the inner input stream.
 int read(byte[] b)
          Reads from the inner input stream, attempting to fill the passed byte array.
 int read(byte[] b, int off, int len)
          Reads the specified number of bytes starting from the specified offset into the specified buffer from the inner input stream.
 long skip(long n)
          Skips the specified number of bytes from the inner input stream.
 
Methods inherited from class java.io.FilterInputStream
mark, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundaryDelimitedInputStream

public BoundaryDelimitedInputStream(java.io.InputStream in,
                                    byte[] boundary)
Constructs a BoundaryDelimitedInputStream using the passed InputStream as the source for the outer stream.

Parameters:
in - the source input stream
boundary - the byte boundary separating sections of this stream
Method Detail

available

public int available()
              throws java.io.IOException
This method will always return 0 because this input stream must always read ahead to determine the location of the boundary.

Overrides:
available in class java.io.FilterInputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close this input stream, and its source input stream. Once this is called, no further data can be read.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException

markSupported

public boolean markSupported()
Returns false. Mark is not support by this input stream.

Overrides:
markSupported in class java.io.FilterInputStream

read

public int read()
         throws java.io.IOException
Reads a single byte from the inner input stream. See the general contract of the read method of InputStream.

Overrides:
read in class java.io.FilterInputStream
Returns:
a signle byte value from the stream in the range of 0-255 or -1 on eof of the inner stream.
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Reads from the inner input stream, attempting to fill the passed byte array. See the general contract of the read method of InputStream.

Overrides:
read in class java.io.FilterInputStream
Parameters:
b - the byte array to populate
Returns:
number of bytes returned in b, -1 on EOF
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Skips the specified number of bytes from the inner input stream. See the general contract of the read method of InputStream.

Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - the number of bytes to skip
Returns:
the number of bytes actually skipped, -1 on EOF
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads the specified number of bytes starting from the specified offset into the specified buffer from the inner input stream. See the general contract of the read method of InputStream.

Overrides:
read in class java.io.FilterInputStream
Parameters:
b - the byte array to populate
off - the offset in the array to start at
len - the number of bytes to read, -1 on EOF
Throws:
java.io.IOException

isOuterStreamClosed

public boolean isOuterStreamClosed()
Returns whether the outer stream is closed.

Returns:
boolean indicating whether the outer stream is closed

printLeftOvers

public void printLeftOvers()