Java Tutorial/File/LongBuffer
Convert ByteBuffer to a LongBuffer
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
public class MainClass {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
System.out.println("Long Buffer");
while (lb.hasRemaining())
System.out.println(lb.position() + " -> " + lb.get());
}
}
/*
*/
Long Buffer 0 -> 97
Create a long ByteBuffer
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
public class Main {
public static void main(String[] argv) throws Exception {
ByteBuffer buf = ByteBuffer.allocate(15);
LongBuffer lbuf = buf.asLongBuffer();
}
}
Loop through a LongBuffer with a while loop
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
public class MainClass {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
System.out.println("Long Buffer");
while (lb.hasRemaining())
System.out.println(lb.position() + " -> " + lb.get());
}
}
/*
*/
Long Buffer 0 -> 97