javax.mail.util
Class SharedByteArrayInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.ByteArrayInputStream
          extended by javax.mail.util.SharedByteArrayInputStream
All Implemented Interfaces:
Closeable, SharedInputStream

public class SharedByteArrayInputStream
extends ByteArrayInputStream
implements SharedInputStream


Field Summary
protected  int start
          Position within shared buffer that this stream starts at.
 
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
 
Constructor Summary
SharedByteArrayInputStream(byte[] buf)
          Create a SharedByteArrayInputStream that shares the entire buffer.
SharedByteArrayInputStream(byte[] buf, int offset, int length)
          Create a SharedByteArrayInputStream using a subset of the array data.
 
Method Summary
 long getPosition()
          Get the position within the output stream, adjusted by the starting offset.
 InputStream newStream(long offset, long end)
          Create a new input stream from this input stream, accessing a subset of the data.
 
Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

start

protected int start
Position within shared buffer that this stream starts at.

Constructor Detail

SharedByteArrayInputStream

public SharedByteArrayInputStream(byte[] buf)
Create a SharedByteArrayInputStream that shares the entire buffer.

Parameters:
buf - The input data.

SharedByteArrayInputStream

public SharedByteArrayInputStream(byte[] buf,
                                  int offset,
                                  int length)
Create a SharedByteArrayInputStream using a subset of the array data.

Parameters:
buf - The source data array.
offset - The starting offset within the array.
length - The length of data to use.
Method Detail

getPosition

public long getPosition()
Get the position within the output stream, adjusted by the starting offset.

Specified by:
getPosition in interface SharedInputStream
Returns:
The adjusted position within the stream.

newStream

public InputStream newStream(long offset,
                             long end)
Create a new input stream from this input stream, accessing a subset of the data. Think of it as a substring operation for a stream. The starting offset must be non-negative. The end offset can by -1, which means use the remainder of the stream.

Specified by:
newStream in interface SharedInputStream
Parameters:
offset - The starting offset.
end - The end offset (which can be -1).
Returns:
An InputStream configured to access the indicated data subrange.


Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.