- java.lang.Object
-
- java.nio.channels.Channels
-
-
Method Summary
Methods Modifier and Type Method and Description 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(AsynchronousByteChannel ch)
Constructs a stream that reads bytes from the given channel.static InputStream
newInputStream(ReadableByteChannel ch)
Constructs a stream that reads bytes from the given channel.static OutputStream
newOutputStream(AsynchronousByteChannel ch)
Constructs a stream that writes bytes to 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.
-
-
-
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 themark
orreset
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
-
newInputStream
public static InputStream newInputStream(AsynchronousByteChannel ch)
Constructs a stream that reads bytes from the given channel.The stream will not be buffered, and it will not support the
mark
orreset
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
- Since:
- 1.7
-
newOutputStream
public static OutputStream newOutputStream(AsynchronousByteChannel ch)
Constructs a stream that writes bytes to the given channel.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
- Since:
- 1.7
-
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 themark
orreset
methods. Closing the stream will in turn cause the channel to be closed.- Parameters:
ch
- The channel from which bytes will be readdec
- The charset decoder to be usedminBufferCap
- 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
behaves in exactly the same way as the expressionChannels.newReader(ch, csname)
Channels.newReader(ch, Charset.forName(csName) .newDecoder(), -1);
- Parameters:
ch
- The channel from which bytes will be readcsName
- 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 writtenenc
- The charset encoder to be usedminBufferCap
- 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
behaves in exactly the same way as the expressionChannels.newWriter(ch, csname)
Channels.newWriter(ch, Charset.forName(csName) .newEncoder(), -1);
- Parameters:
ch
- The channel to which bytes will be writtencsName
- 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
-
-
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 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/nio/channels/channels.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 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.