- java.lang.Object
- 
- java.io.InputStream
- 
- java.io.FilterInputStream
- 
- java.io.BufferedInputStream
- 
- jakarta.mail.util.SharedFileInputStream
 
 
 
 
- 
- All Implemented Interfaces:
- SharedInputStream,- java.io.Closeable,- java.lang.AutoCloseable
 
 public class SharedFileInputStream extends java.io.BufferedInputStream implements SharedInputStream ASharedFileInputStreamis aBufferedInputStreamthat buffers data from the file and supports themarkandresetmethods. It also supports thenewStreammethod that allows you to create other streams that represent subsets of the file. ARandomAccessFileobject is used to access the file data.- Author:
- Bill Shannon
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected longbufposThe file offset that corresponds to the first byte in the read buffer.protected intbufsizeThe normal size of the read buffer.protected longdatalenThe amount of data in this subset of the file.protected java.io.RandomAccessFileinThe file containing the data.protected longstartThe file offset of the start of data in this subset of the file.
 - 
Constructor SummaryConstructors Constructor Description SharedFileInputStream(java.io.File file)Creates aSharedFileInputStreamfor the file.SharedFileInputStream(java.io.File file, int size)Creates aSharedFileInputStreamwith the specified buffer size.SharedFileInputStream(java.lang.String file)Creates aSharedFileInputStreamfor the named fileSharedFileInputStream(java.lang.String file, int size)Creates aSharedFileInputStreamwith the specified buffer size.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of bytes that can be read from this input stream without blocking.voidclose()Closes this input stream and releases any system resources associated with the stream.protected voidfinalize()Force this stream to close.longgetPosition()Return the current position in the InputStream, as an offset from the beginning of the InputStream.voidmark(int readlimit)See the general contract of themarkmethod ofInputStream.booleanmarkSupported()Tests if this input stream supports themarkandresetmethods.java.io.InputStreamnewStream(long start, long end)Return a new InputStream representing a subset of the data from this InputStream, starting atstart(inclusive) up toend(exclusive).intread()See the general contract of thereadmethod ofInputStream.intread(byte[] b, int off, int len)Reads bytes from this stream into the specified byte array, starting at the given offset.voidreset()See the general contract of theresetmethod ofInputStream.longskip(long n)See the general contract of theskipmethod ofInputStream.
 
- 
- 
- 
Field Detail- 
inprotected java.io.RandomAccessFile in The file containing the data. Shared by all related SharedFileInputStreams.
 - 
bufsizeprotected int bufsize The normal size of the read buffer.
 - 
bufposprotected long bufpos The file offset that corresponds to the first byte in the read buffer.
 - 
startprotected long start The file offset of the start of data in this subset of the file.
 - 
datalenprotected long datalen The amount of data in this subset of the file.
 
- 
 - 
Constructor Detail- 
SharedFileInputStreampublic SharedFileInputStream(java.io.File file) throws java.io.IOExceptionCreates aSharedFileInputStreamfor the file.- Parameters:
- file- the file
- Throws:
- java.io.IOException- for errors opening the file
 
 - 
SharedFileInputStreampublic SharedFileInputStream(java.lang.String file) throws java.io.IOExceptionCreates aSharedFileInputStreamfor the named file- Parameters:
- file- the file
- Throws:
- java.io.IOException- for errors opening the file
 
 - 
SharedFileInputStreampublic SharedFileInputStream(java.io.File file, int size) throws java.io.IOExceptionCreates aSharedFileInputStreamwith the specified buffer size.- Parameters:
- file- the file
- size- the buffer size.
- Throws:
- java.io.IOException- for errors opening the file
- java.lang.IllegalArgumentException- if size ≤ 0.
 
 - 
SharedFileInputStreampublic SharedFileInputStream(java.lang.String file, int size) throws java.io.IOExceptionCreates aSharedFileInputStreamwith the specified buffer size.- Parameters:
- file- the file
- size- the buffer size.
- Throws:
- java.io.IOException- for errors opening the file
- java.lang.IllegalArgumentException- if size ≤ 0.
 
 
- 
 - 
Method Detail- 
readpublic int read() throws java.io.IOExceptionSee the general contract of thereadmethod ofInputStream.- Overrides:
- readin class- java.io.BufferedInputStream
- Returns:
- the next byte of data, or -1if the end of the stream is reached.
- Throws:
- java.io.IOException- if an I/O error occurs.
 
 - 
readpublic int read(byte[] b, int off, int len) throws java.io.IOExceptionReads bytes from this stream into the specified byte array, starting at the given offset.This method implements the general contract of the corresponding readInputStream- Overrides:
- readin class- java.io.BufferedInputStream
- Parameters:
- b- destination buffer.
- off- offset at which to start storing bytes.
- len- maximum number of bytes to read.
- Returns:
- the number of bytes read, or -1if the end of the stream has been reached.
- Throws:
- java.io.IOException- if an I/O error occurs.
 
 - 
skippublic long skip(long n) throws java.io.IOExceptionSee the general contract of theskipmethod ofInputStream.- Overrides:
- skipin class- java.io.BufferedInputStream
- Parameters:
- n- the number of bytes to be skipped.
- Returns:
- the actual number of bytes skipped.
- Throws:
- java.io.IOException- if an I/O error occurs.
 
 - 
availablepublic int available() throws java.io.IOExceptionReturns the number of bytes that can be read from this input stream without blocking.- Overrides:
- availablein class- java.io.BufferedInputStream
- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
- java.io.IOException- if an I/O error occurs.
 
 - 
markpublic void mark(int readlimit) See the general contract of themarkmethod ofInputStream.- Overrides:
- markin class- java.io.BufferedInputStream
- Parameters:
- readlimit- the maximum limit of bytes that can be read before the mark position becomes invalid.
- See Also:
- reset()
 
 - 
resetpublic void reset() throws java.io.IOExceptionSee the general contract of theresetmethod ofInputStream.If markposis-1(no mark has been set or the mark has been invalidated), anIOExceptionis thrown. Otherwise,posis set equal tomarkpos.- Overrides:
- resetin class- java.io.BufferedInputStream
- Throws:
- java.io.IOException- if this stream has not been marked or if the mark has been invalidated.
- See Also:
- mark(int)
 
 - 
markSupportedpublic boolean markSupported() Tests if this input stream supports themarkandresetmethods. ThemarkSupportedmethod ofSharedFileInputStreamreturnstrue.- Overrides:
- markSupportedin class- java.io.BufferedInputStream
- Returns:
- a booleanindicating if this stream type supports themarkandresetmethods.
- See Also:
- InputStream.mark(int),- InputStream.reset()
 
 - 
closepublic void close() throws java.io.IOExceptionCloses this input stream and releases any system resources associated with the stream.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Overrides:
- closein class- java.io.BufferedInputStream
- Throws:
- java.io.IOException- if an I/O error occurs.
 
 - 
getPositionpublic long getPosition() Return the current position in the InputStream, as an offset from the beginning of the InputStream.- Specified by:
- getPositionin interface- SharedInputStream
- Returns:
- the current position
 
 - 
newStreampublic java.io.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).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 interface- SharedInputStream
- Parameters:
- start- the starting position
- end- the ending position + 1
- Returns:
- the new stream
 
 - 
finalizeprotected void finalize() throws java.lang.ThrowableForce this stream to close.- Overrides:
- finalizein class- java.lang.Object
- Throws:
- java.lang.Throwable
 
 
- 
 
-