API java : SharedFileInputStream


javax.mail.util
Class SharedFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by javax.mail.util.SharedFileInputStream
All Implemented Interfaces:
Closeable, 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 Summary
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.
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Constructor Summary
SharedFileInputStream(File file)
          Creates a SharedFileInputStream for the file.
SharedFileInputStream(File file, int size)
          Creates a SharedFileInputStream with the specified buffer size.
SharedFileInputStream(String file)
          Creates a SharedFileInputStream for the named file
SharedFileInputStream(String file, int size)
          Creates a SharedFileInputStream with the specified buffer size.
 
Method Summary
 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 the mark method of InputStream.
 boolean markSupported()
          Tests if this input stream supports the mark and reset methods.
 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).
 int read()
          See the general contract of the read method of InputStream.
 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 the reset method of InputStream.
 long skip(long n)
          See the general contract of the skip method of InputStream.
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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()

close

public void close()
           throws IOException
Closes this input stream and releases any system resources associated with the stream.

Specified by:
close in interface Closeable
Overrides:
close in class BufferedInputStream
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 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

finalize

protected void finalize()
                 throws Throwable
Force this stream to close.

Overrides:
finalize in class Object
Throws:
Throwable

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-13098
Document créé le 19/04/08 22:17, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-javaee-rf-javax/mail/util/SharedFileInputStream.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,59 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Etant philosophe, j'ai un problème pour chaque solution.

Robert Zend
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 10:03, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)