Java by API/java.nio/DoubleBuffer — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:31, 31 мая 2010

DoubleBuffer: get()

 
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
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();
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
      System.out.println(db.position() + " -> " + db.get());
  }
}





DoubleBuffer: hasRemaining()

 
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
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();
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
      System.out.println(db.position() + " -> " + db.get());
  }
}





DoubleBuffer: position()

 
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
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();
    DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
    System.out.println("Double Buffer");
    while (db.hasRemaining())
      System.out.println(db.position() + " -> " + db.get());
  }
}





DoubleBuffer: put(double d)

 
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.asDoubleBuffer().put(99471142);
    System.out.println(bb.getDouble());
  }
}