public class SharedFileInputStream
extends java.io.BufferedInputStream
implements jakarta.mail.internet.SharedInputStream
This class implements the Jakarta Mail SharedInputStream
interface for creating substreams by calls to method newStream that read data from the same underlying file.
When creating a SharedFileInputStream
the file from which to read has to be specified:
File file = ...; SharedFileInputStream sfi = new SharedFileInputStream(file);This class uses a special
RandomAccessFileInputStream
to read the data from a basic file that is accessed through a
RandomAccessFile. Anytime when method newStream is called, a new substream is created to read data
from the same underlying file.SharedInputStream| Constructor and Description |
|---|
SharedFileInputStream(java.io.File file)
Creates a SharedFileInputStream for reading from the
given file.
|
SharedFileInputStream(java.io.File file,
int bufSize)
Creates a SharedFileInputStream for reading from the
given file.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Gets the number of bytes that can be read from this stream
without blocking.
|
void |
close()
Closes this input stream.
|
protected void |
finalize()
Performs finalization.
|
long |
getPosition()
Gets the current position of the stream as offset
from the start position.
|
void |
mark(int readlimit)
Marks the current position in this input stream to
start reading from it when method
reset
is called. |
boolean |
markSupported()
Asks whether this input stream does support
mark
and reset. |
java.io.InputStream |
newStream(long start,
long end)
Gets a new SharedInputStream as sub-stream from this InputStream.
|
int |
read()
Reads one byte from this stream.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes from this stream. |
void |
reset()
Resets the stream to the position that has been
previously set by calling method
mark. |
long |
skip(long n)
Skips up to
n bytes of data. |
public SharedFileInputStream(java.io.File file)
throws java.io.IOException
file - the file from which to readjava.io.IOException - if an I/O error occurspublic SharedFileInputStream(java.io.File file,
int bufSize)
throws java.io.IOException
file - the file from which to readbufSize - the size of the internal buffer to be usedjava.io.IOException - if an I/O error occurspublic int read()
throws java.io.IOException
read in class java.io.BufferedInputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from this stream.read in class java.io.BufferedInputStreamb - the byte array into which to read the dataoff - the start offset in blen - the maximum number of bytes to read.-1
if the end of the stream has been reachedjava.io.IOException - if an I/O error occurs while reading from
the streampublic long skip(long n)
throws java.io.IOException
n bytes of data.skip in class java.io.BufferedInputStreamn - the number of bytes to skipjava.io.IOException - error occurs while skippingpublic int available()
throws java.io.IOException
available in class java.io.BufferedInputStreamjava.io.IOException - if an I/O error occurs.public void mark(int readlimit)
reset
is called.mark in class java.io.BufferedInputStreamreadlimit - the number of bytes that can be read before
mark becomes invalidpublic void reset()
mark.reset in class java.io.BufferedInputStreampublic boolean markSupported()
mark
and reset.markSupported in class java.io.BufferedInputStreamtrue since this stream supports mark/resetpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.BufferedInputStreamjava.io.IOException - if an I/O error occurs when closing the stream.public long getPosition()
getPosition in interface jakarta.mail.internet.SharedInputStreampublic java.io.InputStream newStream(long start,
long end)
newStream in interface jakarta.mail.internet.SharedInputStreamstart - the start position in the current streamend - the end position (+1) in the current stream;
-1 if the new stream shall end at the same position
as this streamprotected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable - if an error occurs during finalization