FileDocCategorySizeDatePackage
SharedByteArrayInputStream.javaAPI DocJavaMail 1.4.34176Tue Nov 17 10:38:12 GMT 2009javax.mail.util

SharedByteArrayInputStream

public class SharedByteArrayInputStream extends ByteArrayInputStream implements SharedInputStream
A ByteArrayInputStream that implements the SharedInputStream interface, allowing the underlying byte array to be shared between multiple readers.
author
Bill Shannon
since
JavaMail 1.4

Fields Summary
protected int
start
Position within shared buffer that this stream starts at.
Constructors Summary
public SharedByteArrayInputStream(byte[] buf)
Create a SharedByteArrayInputStream representing the entire byte array.

param
buf the byte array


             		       
       
	super(buf);
    
public SharedByteArrayInputStream(byte[] buf, int offset, int length)
Create a SharedByteArrayInputStream representing the part of the byte array from offset for length bytes.

param
buf the byte array
param
offset offset in byte array to first byte to include
param
length number of bytes to include

	super(buf, offset, length);
	start = offset;
    
Methods Summary
public longgetPosition()
Return the current position in the InputStream, as an offset from the beginning of the InputStream.

return
the current position

	return pos - start;
    
public java.io.InputStreamnewStream(long start, long end)
Return a new InputStream representing a subset of the data from this InputStream, starting at start (inclusive) up to end (exclusive). start must be non-negative. If end is -1, the new stream ends at the same place as this stream. The returned InputStream will also implement the SharedInputStream interface.

param
start the starting position
param
end the ending position + 1
return
the new stream

	if (start < 0)
	    throw new IllegalArgumentException("start < 0");
	if (end == -1)
	    end = count - this.start;
	return new SharedByteArrayInputStream(buf,
				this.start + (int)start, (int)(end - start));