Home » nio » Page 2

Tag Archives: nio

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 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 »

Jetty NIO Example

In this example, we will show how to use jetty with NIO based connector for server side communications with clients. Before Jetty 9 , there were both blocking Input/Output (BIO) and non-blocking Input/Output (NIO) and one has to specify protocol and implementation used through connector. Jetty 9 now only offers NIO connector and protocol is configured through collection of ConnectionFactory ...

Read More »

Java Nio SSL Example

This is an example of a non-blocking I/O provided by java.nio using SSL handshake.                     1. Definition of Secure Sockets Layer Protocol (SSL) SSL is the secure communication protocol of choice for a large part of the Internet community. There are many applications of SSL in existence, since it is capable ...

Read More »

Java Direct ByteBuffer Example

This example shows the usage of direct ByteBuffer. ByteBuffer is an abstract class, extends Buffer and implements Comparable<ByteBuffer>. This class is defined in the java.nio package. A buffer is a container for a fixed amount of data of a specific primitive type. There is a buffer class for each non-boolean primitive type. A ByteBuffer is a sub class of Buffer ...

Read More »

Java Delete File Example

In this example, we are going to explain how to delete a file in Java. Of course, Java offers a very convenient API to perform deletion and creation. Most of them are placed in File class. We are going to use delete() methods that delete the file or directory. If the file is deleted successfully, the methods returns true, else ...

Read More »