NIO and NIO.2 Examples (original) (raw)
The examples in the following table show how to use the NIO APIs.
Source File | Description |
---|---|
<Grep.java> | Searches a list of files for lines that match a given regular-expression pattern. Demonstrates NIO mapped byte buffers, charsets, and regular expressions. |
<Sum.java> | Computes 16-bit checksums for a list of files. Uses NIO mapped byte buffers for speed. |
<TimeQuery.java> | Asks a list of hosts what time it is. Is a simple, blocking program that demonstrates NIO socket channels (connection and reading), buffer handling, charsets, and regular expressions. |
<TimeServer.java> | Listens for connections and tells callers what time it is. Is a simple, blocking program that demonstrates NIO socket channels (accepting and writing), buffer handling, charsets, and regular expressions. |
<Ping.java> | Connects to each of a list of hosts and measures the time required to complete the connection. Uses a selector and two additional threads to demonstrate non-blocking connects and the multithreaded use of a selector. |
<NBTimeServer.java> | Implements a non-blocking Internet time server. |
The NIO.2 examples in the following table can be accessed in your JDK 7 installation under<_JAVAHOME_>/sample/nio
.
Source File | Description |
---|---|
file/Chmod.java | Changes the permissions of files in a manner similar to the chmod(1) utility. |
file/Copy.java | Copies files in a manner similar to the cp(1) utility. |
file/DiskUsage.java | Prints out disk space information similar to the df(1M) utility. |
file/FileType.java | Prints out a file's type. |
file/WatchDir.java | Watches a directory (or tree) for changes to files. |
file/Xdd.java | Lists, gets, and deletes the user-defined attributes of a file. |
multicast/MulticastAdress.java | Parses and represents a multicast address. |
multicast/Reader.java | Reads a message from a multicast datagram. |
multicast/Sender.java | Sends a message in a multicast datagram to a given group. |
server/README.txt | This directory contains a simple NIO-based HTTP/HTTPS server example. See the README.txt file for further information. |