Please enable JavaScript.
Coggle requires JavaScript to display documents.
Java Base (NIO (Channels (DatagramChannel - Read and write data across a…
Java Base
NIO
Channels
-
-
-
-
FileChannel Transfer - The FileChannel class has methods which allow its data to be directly transfered to and from the other channels
Buffers
Data is read from a channel into a buffer or written from a buffer into a channel. It is essentially a block of memory. A buffer is non-blocking, so other actions can be made while a buffer is being written/read
buffer.flip() flips the mode between read and write. Must also be cleared if it needs to be used again
Buffer object for each data type (eg. int, byte etc)
When data is written into a buffer, it is done so from position=0 until capacity. When the mode is flipped, position is reset back to 0 and read until limit (number of values until data stream is read)
Buffer Scatter/Gather - A buffer array can be used to read data from a channel into multiple buffers. The buffers are filled in order of their index in the array, so when one is full, the next is used. The reverse works, where data is written from mutiple buffers into a single channel
Selector
Can monitor multiple channels at once, eg. waiting for data
Channels need to be registered for use by the selector, and given a mode which the selector monitors. This is either connect, accept, read or write. You can listen for more than one mode
SelectionKey - When a channel is registered, a SelectionKey is returned. This just contains information about that pairing
Pipe
One way connection between threads. The pipe object is created on one thread and passed into a second.
The source channel is used to send data, and the sink channel recieves it
IO
Streams
Endless flow of data. Can be read from or written to and be byte-based(Input/Output Stream) or character-based(Reader/Writer)
-
-
Files
FileInputStream/FileReader - Used to read a file in a linear fashion, it will read the file from the start until specified
RandomAccessFile - Allows you to move around in a file and both read and write in places, so that you can overwrite/append/delete/read etc parts of it
-
-
Pipes
-
PipedInputStream/PipedOutputStream - Allows data to be transmitted as bytes. The output can be sent to many inputs, but not vice versa.
Net
TCP/IP
Client opens TCP connection and then sends requests(communications) to the server which may or may not be responded to. The client then closes the connection as well.
Sockets
-
ServerSocket - The server's implementation that listens to traffic coming in via the specified port. Assigns a socket itself that listens to the client.
To read/write to sockets, use the getOutputStream() method to create the stream.
UDP
No connection between client/server. Client sends data to server, but will never know if it was received. Less overhead. Useful for data that needs to send quickly and missing a bit won't matter (eg. live data)