Channel, charset, encoder, decoder, selector, FileChannel class in java.nio package

Channel: Channel is used to represent open connection to input or output devices.

Charset, encoder and decoder in java.nio.charset package: The process by which bytes are mapped to characters is defined by charsets. An encoder is used to encode a sequence of characters to bytes and a decoder is used to decode a sequence of bytes to characters.

Selector: By using a selector input and output can be achieved through multiple channels. It is defined in java.nio.channels package.

To wrap channels, FileChannel class is used in java.nio package.

Methods defined by FileChannel class:

read( ) method: It is used to return number of bytes read from calling channel.


To read in bb till buffer is full or no input:

abstract int read(ByteBuffer bb)

By using starting point as start:

abstract int read(ByteBuffer bb, long start)

write( ) method: It is used to write to a calling channel.


To write bb to calling channel:

abstract int write(ByteBuffer bb)

By using starting point as start:

abstract int write(ByteBuffer bb, long start)

Leave a Reply