Home » Core Java » nio (page 2)

nio

Java Nio Iterate Over Files in Directory

This example will demonstrate iterating over the files and directories recursively from a root directory. The example program will utilize some of the Java NIO features. Central to this example are the DirectoryStream, Filter, Path and Paths classes.                    1. Introduction Before diving into the example program an understanding of the 4 abstractions ...

Read More »

Java Nio HeapByteBuffer Example

This example demonstrates the usage of the Java Nio HeapByteBuffer. The Java Nio HeapByteBuffer is an odd class, one you will never reference directly and for good reason, it’s package private. Although it’s use is almost guaranteed when working with ByteBuffers unless you opt for a DirectByteBuffer (off heap). By virtue of extending ByteBuffer, it also happens to extend Buffer and implement Comparable.   ...

Read More »

Java Nio Async HTTP Client Example

This article is an example of how to build a simple asynchronous Http client using Java Nio. This example will make use of the httpbin service for much of it’s test cases, which can also be verified via postman or curl. Although the examples work, this is by no means a production ready. The exhaustive Http client implementation was merely an ...

Read More »

Java Nio ByteBuffer Example

This article is a tutorial on demonstrating the usage of the Java Nio ByteBuffer. All examples are done in the form of unit tests to easily prove the expectations of the API.                 1. Introduction The ByteBuffer class is an abstract class which also happens to extend Buffer and implement Comparable. A Buffer is simply a ...

Read More »

Java Nio Large File Transfer Tutorial

This article is a tutorial on transferring a large file using Java Nio. It will take shape via two examples demonstrating a simple local file transfer from one location on hard disk to another and then via sockets from one remote location to another remote location. Table Of Contents 1. Introduction 2. Technologies used 3. FileChannel 4. Background 5. Program 5.1. ...

Read More »

Java Nio Heartbeat Example

This article is a tutorial on implementing a simple Java NIO Heartbeat. This example will take the form of “n” number of “Broadcast” mode processes which will multicast data via UDP to “n” number of “Subscribe” processes that have expressed interest in receiving said traffic.                 1. Introduction This article builds on three ...

Read More »

Java Nio Echo Server Tutorial

This article is a tutorial on implementing a simple Java NIO “echo server”. This example will take the form of a rather simple client server application whereby a client or many clients will connect to a running server and post message(s) to the server which will in turn be “echoed” back to the respective clients.           ...

Read More »

Java Nio Asynchronous Channels Tutorial

This article is a tutorial on the Asynchronous Channels API which was released as part of Java 7. The API can be viewed here. The example code will demonstrate use of the core abstractions of this API and will capture the essence of using the API. Table Of Contents 1. Introduction 2. Technologies used 3. API interaction 4. AsynchronousChannel 5. ...

Read More »

Java Nio Tutorial for Beginners

This article is a beginners tutorial on Java NIO (New IO). We will take a high level look at this API which provides an alternative to Java IO. The Java NIO API can be viewed here. The example code demonstrates use of the core abstractions in this topic. The example code in this article was built and run using: Java ...

Read More »

Java Nio Write File Example

With this example we are going to demonstrate how to use the Non-blocking I/O API, or NIO.2 API (NIO API) for short, to write data to a file. The examples in this article are compiled and run in a Mac OS unix environment. Please note that Java SE 8 is required to run the code in this article.       ...

Read More »