- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- javax.mail.util.SharedFileInputStream
-
- All Implemented Interfaces:
- Closeable, AutoCloseable, SharedInputStream
public class SharedFileInputStream extends BufferedInputStream implements SharedInputStream
ASharedFileInputStream
is aBufferedInputStream
that buffers data from the file and supports themark
andreset
methods. It also supports thenewStream
method that allows you to create other streams that represent subsets of the file. ARandomAccessFile
object is used to access the file data.Note that when the SharedFileInputStream is closed, all streams created with the
newStream
method are also closed. This allows the creator of the SharedFileInputStream object to control access to the underlying file and ensure that it is closed when needed, to avoid leaking file descriptors. Note also that this behavior contradicts the requirements of SharedInputStream and may change in a future release.- Since:
- JavaMail 1.4
- Author:
- Bill Shannon
-
-
Field Summary
Fields Modifier and Type Field and Description protected long
bufpos
The file offset that corresponds to the first byte in the read buffer.protected int
bufsize
The normal size of the read buffer.protected long
datalen
The amount of data in this subset of the file.protected RandomAccessFile
in
The file containing the data.protected long
start
The file offset of the start of data in this subset of the file.
-
Constructor Summary
Constructors Constructor and Description SharedFileInputStream(File file)
Creates aSharedFileInputStream
for the file.SharedFileInputStream(File file, int size)
Creates aSharedFileInputStream
with the specified buffer size.SharedFileInputStream(String file)
Creates aSharedFileInputStream
for the named fileSharedFileInputStream(String file, int size)
Creates aSharedFileInputStream
with the specified buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int
available()
Returns the number of bytes that can be read from this input stream without blocking.void
close()
Closes this input stream and releases any system resources associated with the stream.protected void
finalize()
Force this stream to close.long
getPosition()
Return the current position in the InputStream, as an offset from the beginning of the InputStream.void
mark(int readlimit)
See the general contract of themark
method ofInputStream
.boolean
markSupported()
Tests if this input stream supports themark
andreset
methods.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).int
read()
See the general contract of theread
method ofInputStream
.int
read(byte[] b, int off, int len)
Reads bytes from this stream into the specified byte array, starting at the given offset.void
reset()
See the general contract of thereset
method ofInputStream
.long
skip(long n)
See the general contract of theskip
method ofInputStream
.-
Methods inherited from class java.io.FilterInputStream
read
-
-
-
-
Field Detail
-
in
protected RandomAccessFile in
The file containing the data. Shared by all related SharedFileInputStreams.
-
bufsize
protected int bufsize
The normal size of the read buffer.
-
bufpos
protected long bufpos
The file offset that corresponds to the first byte in the read buffer.
-
start
protected long start
The file offset of the start of data in this subset of the file.
-
datalen
protected long datalen
The amount of data in this subset of the file.
-
-
Constructor Detail
-
SharedFileInputStream
public SharedFileInputStream(File file) throws IOException
Creates aSharedFileInputStream
for the file.- Parameters:
file
- the file- Throws:
IOException
-
SharedFileInputStream
public SharedFileInputStream(String file) throws IOException
Creates aSharedFileInputStream
for the named file- Parameters:
file
- the file- Throws:
IOException
-
SharedFileInputStream
public SharedFileInputStream(File file, int size) throws IOException
Creates aSharedFileInputStream
with the specified buffer size.- Parameters:
file
- the filesize
- the buffer size.- Throws:
IllegalArgumentException
- if size <= 0.IOException
-
SharedFileInputStream
public SharedFileInputStream(String file, int size) throws IOException
Creates aSharedFileInputStream
with the specified buffer size.- Parameters:
file
- the filesize
- the buffer size.- Throws:
IllegalArgumentException
- if size <= 0.IOException
-
-
Method Detail
-
read
public int read() throws IOException
See the general contract of theread
method ofInputStream
.- Overrides:
read
in classBufferedInputStream
- Returns:
- the next byte of data, or
-1
if the end of the stream is reached. - Throws:
IOException
- if an I/O error occurs.
-
read
public int read(byte[] b, int off, int len) throws IOException
Reads bytes from this stream into the specified byte array, starting at the given offset.This method implements the general contract of the corresponding
method of theread
class.InputStream
- Overrides:
read
in classBufferedInputStream
- 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
-1
if the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
-
skip
public long skip(long n) throws IOException
See the general contract of theskip
method ofInputStream
.- Overrides:
skip
in classBufferedInputStream
- Parameters:
n
- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException
- if an I/O error occurs.
-
available
public int available() throws IOException
Returns the number of bytes that can be read from this input stream without blocking.- Overrides:
available
in classBufferedInputStream
- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
IOException
- if an I/O error occurs.
-
mark
public void mark(int readlimit)
See the general contract of themark
method ofInputStream
.- Overrides:
mark
in classBufferedInputStream
- Parameters:
readlimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.- See Also:
reset()
-
reset
public void reset() throws IOException
See the general contract of thereset
method ofInputStream
.If
markpos
is-1
(no mark has been set or the mark has been invalidated), anIOException
is thrown. Otherwise,pos
is set equal tomarkpos
.- Overrides:
reset
in classBufferedInputStream
- Throws:
IOException
- if this stream has not been marked or if the mark has been invalidated.- See Also:
mark(int)
-
markSupported
public boolean markSupported()
Tests if this input stream supports themark
andreset
methods. ThemarkSupported
method ofSharedFileInputStream
returnstrue
.- Overrides:
markSupported
in classBufferedInputStream
- Returns:
- a
boolean
indicating if this stream type supports themark
andreset
methods. - See Also:
InputStream.mark(int)
,InputStream.reset()
-
close
public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream.- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classBufferedInputStream
- Throws:
IOException
- if an I/O error occurs.
-
getPosition
public long getPosition()
Return the current position in the InputStream, as an offset from the beginning of the InputStream.- Specified by:
getPosition
in interfaceSharedInputStream
- Returns:
- the current position
-
newStream
public 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).start
must be non-negative. Ifend
is -1, the new stream ends at the same place as this stream. The returned InputStream will also implement the SharedInputStream interface.- Specified by:
newStream
in interfaceSharedInputStream
- Parameters:
start
- the starting positionend
- the ending position + 1- Returns:
- the new stream
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/mail/util/SharedFileInputStream.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.