Java by API/java.nio/IntBuffer

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

IntBuffer: get()

   <source lang="java">

import java.nio.ByteBuffer; import java.nio.IntBuffer; 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();
   IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
   System.out.println("Int Buffer");
   while (ib.hasRemaining())
     System.out.println(ib.position() + " -> " + ib.get());
 }

}

 </source>
   
  
 
  



IntBuffer: hasRemaining()

   <source lang="java">

import java.nio.ByteBuffer; import java.nio.IntBuffer; 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();
   IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
   System.out.println("Int Buffer");
   while (ib.hasRemaining())
     System.out.println(ib.position() + " -> " + ib.get());
 }

}

 </source>
   
  
 
  



IntBuffer: position()

   <source lang="java">

import java.nio.ByteBuffer; import java.nio.IntBuffer; 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();
   IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
   System.out.println("Int Buffer");
   while (ib.hasRemaining())
     System.out.println(ib.position() + " -> " + ib.get());
 }

}

 </source>
   
  
 
  



IntBuffer: put(int i)

   <source lang="java">

import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.IntBuffer; import java.nio.channels.FileChannel; public class Main {

 public static void main(String[] args) throws IOException {
   FileChannel fc = new RandomAccessFile(new File("temp.tmp"), "rw").getChannel();
   IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size()).asIntBuffer();
   ib.put(0);
   for (int i = 1; i < 10; i++)
     ib.put(ib.get(i - 1));
   fc.close();
 }

}

 </source>