API java : Channels


java.nio.channels
Class Channels

java.lang.Object
  extended by java.nio.channels.Channels

public final class Channels
extends Object

Utility methods for channels and streams.

This class defines static methods that support the interoperation of the stream classes of the java.io package with the channel classes of this package.

Since:
1.4

Method Summary
static ReadableByteChannel newChannel(InputStream in)
          Constructs a channel that reads bytes from the given stream.
static WritableByteChannel newChannel(OutputStream out)
          Constructs a channel that writes bytes to the given stream.
static InputStream newInputStream(ReadableByteChannel ch)
          Constructs a stream that reads bytes from the given channel.
static OutputStream newOutputStream(WritableByteChannel ch)
          Constructs a stream that writes bytes to the given channel.
static Reader newReader(ReadableByteChannel ch, CharsetDecoder dec, int minBufferCap)
          Constructs a reader that decodes bytes from the given channel using the given decoder.
static Reader newReader(ReadableByteChannel ch, String csName)
          Constructs a reader that decodes bytes from the given channel according to the named charset.
static Writer newWriter(WritableByteChannel ch, CharsetEncoder enc, int minBufferCap)
          Constructs a writer that encodes characters using the given encoder and writes the resulting bytes to the given channel.
static Writer newWriter(WritableByteChannel ch, String csName)
          Constructs a writer that encodes characters according to the named charset and writes the resulting bytes to the given channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInputStream

public static InputStream newInputStream(ReadableByteChannel ch)
Constructs a stream that reads bytes from the given channel.

The read methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non-blocking mode. The stream will not be buffered, and it will not support the mark or reset methods. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters:
ch - The channel from which bytes will be read
Returns:
A new input stream

newOutputStream

public static OutputStream newOutputStream(WritableByteChannel ch)
Constructs a stream that writes bytes to the given channel.

The write methods of the resulting stream will throw an IllegalBlockingModeException if invoked while the underlying channel is in non-blocking mode. The stream will not be buffered. The stream will be safe for access by multiple concurrent threads. Closing the stream will in turn cause the channel to be closed.

Parameters:
ch - The channel to which bytes will be written
Returns:
A new output stream

newChannel

public static ReadableByteChannel newChannel(InputStream in)
Constructs a channel that reads bytes from the given stream.

The resulting channel will not be buffered; it will simply redirect its I/O operations to the given stream. Closing the channel will in turn cause the stream to be closed.

Parameters:
in - The stream from which bytes are to be read
Returns:
A new readable byte channel

newChannel

public static WritableByteChannel newChannel(OutputStream out)
Constructs a channel that writes bytes to the given stream.

The resulting channel will not be buffered; it will simply redirect its I/O operations to the given stream. Closing the channel will in turn cause the stream to be closed.

Parameters:
out - The stream to which bytes are to be written
Returns:
A new writable byte channel

newReader

public static Reader newReader(ReadableByteChannel ch,
                               CharsetDecoder dec,
                               int minBufferCap)
Constructs a reader that decodes bytes from the given channel using the given decoder.

The resulting stream will contain an internal input buffer of at least minBufferCap bytes. The stream's read methods will, as needed, fill the buffer by reading bytes from the underlying channel; if the channel is in non-blocking mode when bytes are to be read then an IllegalBlockingModeException will be thrown. The resulting stream will not otherwise be buffered, and it will not support the mark or reset methods. Closing the stream will in turn cause the channel to be closed.

Parameters:
ch - The channel from which bytes will be read
dec - The charset decoder to be used
minBufferCap - The minimum capacity of the internal byte buffer, or -1 if an implementation-dependent default capacity is to be used
Returns:
A new reader

newReader

public static Reader newReader(ReadableByteChannel ch,
                               String csName)
Constructs a reader that decodes bytes from the given channel according to the named charset.

An invocation of this method of the form

  1. Channels.newReader(ch, csname)
behaves in exactly the same way as the expression
  1. Channels.newReader(ch,
  2. Charset.forName(csName)
  3. .newDecoder(),
  4. -1);

Parameters:
ch - The channel from which bytes will be read
csName - The name of the charset to be used
Returns:
A new reader
Throws:
UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine

newWriter

public static Writer newWriter(WritableByteChannel ch,
                               CharsetEncoder enc,
                               int minBufferCap)
Constructs a writer that encodes characters using the given encoder and writes the resulting bytes to the given channel.

The resulting stream will contain an internal output buffer of at least minBufferCap bytes. The stream's write methods will, as needed, flush the buffer by writing bytes to the underlying channel; if the channel is in non-blocking mode when bytes are to be written then an IllegalBlockingModeException will be thrown. The resulting stream will not otherwise be buffered. Closing the stream will in turn cause the channel to be closed.

Parameters:
ch - The channel to which bytes will be written
enc - The charset encoder to be used
minBufferCap - The minimum capacity of the internal byte buffer, or -1 if an implementation-dependent default capacity is to be used
Returns:
A new writer

newWriter

public static Writer newWriter(WritableByteChannel ch,
                               String csName)
Constructs a writer that encodes characters according to the named charset and writes the resulting bytes to the given channel.

An invocation of this method of the form

  1. Channels.newWriter(ch, csname)
behaves in exactly the same way as the expression
  1. Channels.newWriter(ch,
  2. Charset.forName(csName)
  3. .newEncoder(),
  4. -1);

Parameters:
ch - The channel to which bytes will be written
csName - The name of the charset to be used
Returns:
A new writer
Throws:
UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine

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-782
Document créé le 27/07/06 13:57, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/nio/channels/Channels.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,82 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Le courage croît en osant et la peur en hésitant.

Proverbe romain
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 21:40, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)