Buffer (Buffer):
First, is responsible for data access in the Java NIO. Buffer is an array. For storing data of different data types
according to the different types of data (except Boolean), to provide the corresponding buffer types:
the ByteBuffer
CharBuffer
ShortBuffer
IntBuffer
LongBuffer
FloatBuffer
the DoubleBuffer
almost the same above buffer management, () Gets allocate buffers by
two, two core method of accessing data buffers:
PUT (): the data stored in the buffer to
get (): Get the data buffer
three, four buffer core attributes:
capacity: capacity, indicates that the buffer the maximum capacity of the stored data. Once the statement can not be changed.
limit: limit, it represents the buffer size of data can be operated. (Limit the data can not be read)
position: position, indicates that the buffer is operating in the position data.
mark: mark indicates the recording position of the current position. Mark can be restored by the reset () the position of
0 <= mark <= position < = limit <= capacity
four, direct buffers not directly Buffer:
Non-direct buffers: () method of dispensing by the allocate buffers, buffer District built on the JVM memory
Direct Buffer: () method for allocating buffers by direct allocateDirect, the buffer is established in physical memory. Can improve efficiency
Channel (Channel):
First, for connecting the source node and the destination node. Responsible for the transmission of data in a buffer in Java NIO. Channel data is not stored in itself, and therefore needs to be transmitted with the buffer.
Second, the main channel of the implementation class
java.nio.channels.Channel Interface:
| --FileChannel
| --SocketChannel
| --ServerSocketChannel
| --DatagramChannel
Third, access to channel
1. Java provides support for the passage of getChannel class () method
local IO:
FileInputStream / FileOutputStream
RandomAccessFile
network IO:
the Socket
ServerSocket
DatagramSocket
2. in the 1.7 NIO.2 JDK provides a static method for each channel Open ()
3. Files of NIO.2 of newByteChannel tools in the JDK 1.7 ( )
data transmission between the four channels
transferFrom ()
transferTo ()
V. dispersion (the Scatter) and aggregation (gather)
dispersion read (Scattering reads): the data channel is dispersed into a plurality of buffers
aggregate write ( gathering Writes): aggregating a plurality of data buffers into the passage
Sixth, the character set: the Charset
encoding: string -> byte array
decoding: byte array -> string