Java by API/java.nio/FloatBuffer — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 20:43, 31 мая 2010
Содержание
FloatBuffer: get()
<source lang="java">
import java.nio.ByteBuffer; import java.nio.FloatBuffer; public class Main {
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" }); bb.rewind(); FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer(); System.out.println("Float Buffer"); while (fb.hasRemaining()) System.out.println(fb.position() + " -> " + fb.get()); }
}
</source>
FloatBuffer: hasRemaining()
<source lang="java">
import java.nio.ByteBuffer; import java.nio.FloatBuffer; public class Main {
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" }); bb.rewind(); FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer(); System.out.println("Float Buffer"); while (fb.hasRemaining()) System.out.println(fb.position() + " -> " + fb.get()); }
}
</source>
FloatBuffer: position()
<source lang="java">
import java.nio.ByteBuffer; import java.nio.FloatBuffer; public class Main {
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" }); bb.rewind(); FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer(); System.out.println("Float Buffer"); while (fb.hasRemaining()) System.out.println(fb.position() + " -> " + fb.get()); }
}
</source>
FloatBuffer: put(float f)
<source lang="java">
import java.nio.ByteBuffer; public class Main {
private static final int BSIZE = 1024; public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asFloatBuffer().put(99471142); System.out.println(bb.getFloat()); }
}
</source>