javax.mail.util

Class SharedFileInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable, SharedInputStream

    public class SharedFileInputStream
    extends BufferedInputStream
    implements SharedInputStream
    A SharedFileInputStream is a BufferedInputStream that buffers data from the file and supports the mark and reset methods. It also supports the newStream method that allows you to create other streams that represent subsets of the file. A RandomAccessFile 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 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 a SharedFileInputStream for the file.
        Parameters:
        file - the file
        Throws:
        IOException
      • SharedFileInputStream

        public SharedFileInputStream(String file)
                              throws IOException
        Creates a SharedFileInputStream for the named file
        Parameters:
        file - the file
        Throws:
        IOException
      • SharedFileInputStream

        public SharedFileInputStream(File file,
                                     int size)
                              throws IOException
        Creates a SharedFileInputStream with the specified buffer size.
        Parameters:
        file - the file
        size - the buffer size.
        Throws:
        IllegalArgumentException - if size <= 0.
        IOException
      • SharedFileInputStream

        public SharedFileInputStream(String file,
                                     int size)
                              throws IOException
        Creates a SharedFileInputStream with the specified buffer size.
        Parameters:
        file - the file
        size - the buffer size.
        Throws:
        IllegalArgumentException - if size <= 0.
        IOException
    • Method Detail

      • read

        public int read()
                 throws IOException
        See the general contract of the read method of InputStream.
        Overrides:
        read in class BufferedInputStream
        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 read method of the InputStream class.

        Overrides:
        read in class 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 -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 the skip method of InputStream.
        Overrides:
        skip in class BufferedInputStream
        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 class BufferedInputStream
        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 the mark method of InputStream.
        Overrides:
        mark in class BufferedInputStream
        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 the reset method of InputStream.

        If markpos is -1 (no mark has been set or the mark has been invalidated), an IOException is thrown. Otherwise, pos is set equal to markpos.

        Overrides:
        reset in class BufferedInputStream
        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 the mark and reset methods. The markSupported method of SharedFileInputStream returns true.
        Overrides:
        markSupported in class BufferedInputStream
        Returns:
        a boolean indicating if this stream type supports the mark and reset methods.
        See Also:
        InputStream.mark(int), InputStream.reset()
      • getPosition

        public long getPosition()
        Return the current position in the InputStream, as an offset from the beginning of the InputStream.
        Specified by:
        getPosition in interface SharedInputStream
        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 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.
        Specified by:
        newStream in interface SharedInputStream
        Parameters:
        start - the starting position
        end - the ending position + 1
        Returns:
        the new stream

Traduction non disponible

Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Version en cache

21/08/2025 17:18:06 Cette version de la page est en cache (à la date du 21/08/2025 17:18:06) afin d'accélérer le traitement.
Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.

Document créé le 19/04/2008, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/mail/util/SharedFileInputStream.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :fr Manuel PHP : https://docs.oracle.com, SharedFileInputStream (Java(TM) EE 7 Specification APIs)

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.