Package javax.mail.util
Class SharedByteArrayInputStream
java.lang.Object
java.io.InputStream
java.io.ByteArrayInputStream
javax.mail.util.SharedByteArrayInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,SharedInputStream
A ByteArrayInputStream that implements the SharedInputStream interface,
allowing the underlying byte array to be shared between multiple readers.
- Since:
- JavaMail 1.4
-
Constructor Summary
ConstructorsConstructorDescriptionSharedByteArrayInputStream(byte[] buf) Create a SharedByteArrayInputStream representing the entire byte array.SharedByteArrayInputStream(byte[] buf, int offset, int length) Create a SharedByteArrayInputStream representing the part of the byte array fromoffsetforlengthbytes. -
Method Summary
Modifier and TypeMethodDescriptionlongReturn the current position in the InputStream, as an offset from the beginning of the InputStream.newStream(long start, long end) Return a new InputStream representing a subset of the data from this InputStream, starting atstart(inclusive) up toend(exclusive).Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, readAllBytes, readNBytes, reset, skip, transferToMethods inherited from class java.io.InputStream
nullInputStream, read, readNBytes, skipNBytes
-
Constructor Details
-
SharedByteArrayInputStream
public SharedByteArrayInputStream(byte[] buf) Create a SharedByteArrayInputStream representing the entire byte array.- Parameters:
buf- the byte array
-
SharedByteArrayInputStream
public SharedByteArrayInputStream(byte[] buf, int offset, int length) Create a SharedByteArrayInputStream representing the part of the byte array fromoffsetforlengthbytes.- Parameters:
buf- the byte arrayoffset- offset in byte array to first byte to includelength- number of bytes to include
-
-
Method Details
-
getPosition
public long getPosition()Return the current position in the InputStream, as an offset from the beginning of the InputStream.- Specified by:
getPositionin interfaceSharedInputStream- Returns:
- the current position
-
newStream
Return a new InputStream representing a subset of the data from this InputStream, starting atstart(inclusive) up toend(exclusive).startmust be non-negative. Ifendis -1, the new stream ends at the same place as this stream. The returned InputStream will also implement the SharedInputStream interface.- Specified by:
newStreamin interfaceSharedInputStream- Parameters:
start- the starting positionend- the ending position + 1- Returns:
- the new stream
-