CORE API / NOTES</>↗Core API25 Feb 2010
The example below show you how to get the absolute value of a number. To get the absolute value or the abs value of a number we use the Math.abs() method call. The Math.abs() method is an overloaded that can accept value in type of double, float, int or long. package org.kodejava.math; public class GetAbsoluteValueExample […]
CORE API / NOTES</>↗Core API25 Feb 2010
In this example you’ll see how to read data from buffer using FileChannel.write() method call. Reading from a buffer means that you are writing data into the channel object. In the snippet below the data from our dummy buffer will be read and written into the result.txt file. package org.kodejava.io; import java.io.File; import java.io.FileOutputStream; import […]
CORE API / NOTES</>↗Core API23 Feb 2010
A buffer can be read or written. To change the mode between the write mode and read mode we use the flip() method call on the buffer. There are few things that you should know when you change between the write mode to the read mode. A buffer have the capacity, position and limit properties. […]
CORE API / NOTES</>↗Core API22 Feb 2010
The snippet below show you how to write some bytes into the java.nio.ByteBuffer object through a call to the put() method. package org.kodejava.io; import java.nio.ByteBuffer; public class BufferPut { public static void main(String[] args) { ByteBuffer buffer = ByteBuffer.allocate(32); buffer.put((byte) 65); buffer.put((byte) 66); buffer.put((byte) 67); buffer.put((byte) 68); buffer.put((byte) 69); // Writes a sequence of bytes […]
CORE API / NOTES</>↗Core API18 Feb 2010
The example below show how to use a FileChannel to read some data into a Buffer. We create a FileChannel from a FileInputStream instance. Because a channel reads data into buffer we need to create a ByteBuffer and set its capacity. Read data from a channel into buffer using the FileChannel.read() method. To read out […]
CORE API / NOTES</>↗Core API16 Feb 2010
This post show you how to use the java.nio buffer such as ByteBuffer, CharBuffer, DoubleBuffer, etc. To create a buffer you can use the allocate(int capacity) method. Each buffer object has the allocate(int capacity) method. You need to pass the value of the capacity of the buffer to be created when calling this method. package […]