Convert between ByteBuffer and byte array
// Create a byte array byte[] bytes = new byte[10]; // Wrap a byte array into a buffer ByteBuffer buf = ByteBuffer.wrap(bytes); // Retrieve bytes between the position and limit // (see Putting Bytes...
View ArticleCreate direct and non-direct ByteBuffer
In this example we are going to demonstrate several methods of creating a direct (memory-mapped) and non-direct ByteBuffer in Java. Given a direct byte buffer, the Java virtual machine will make a best...
View ArticlePut byte into ByteBuffer
This is an example of how to put bytes into a ByteBuffer in Java. Additionally we will demonstrate several of ByteBuffer‘s API methods in order to share some light on how to randomly write data to it....
View ArticleGet byte from ByteBuffer
With this example we are going to demonstrate how to read bytes from a ByteBuffer. Additionally we will show you several of ByteBuffer‘s API methods in order to share some light on how to randomly...
View ArticleUse ByteBuffer to store Strings
This is an example of how to store Strings using a ByteBuffer in Java. In order to use a ByteBuffer to store Strings in Java we have to : Allocate a new ByteBuffer and set its size to a number large...
View ArticleUse ByteBuffer for non-byte Java types buffering
In this example we will demonstrate how to perform non-byte Java types buffering using a ByteBuffer in Java. In particular we are going to show you how to use a ByteBuffer to store the following Java...
View ArticleWrite/Append to File with ByteBuffer
With this is example we are going to demonstrate how to write/append data to a file in Java using a ByteBuffer. Particularly we are going to read data from a source file and append them to the...
View Article