ByteBuffer: getDouble() : ByteBuffer « java.nio « Java by API






ByteBuffer: getDouble()

   
import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
  public static void main(String[] args) throws Exception{
    File aFile = new File("primes.txt");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    ByteBuffer buf = ByteBuffer.allocateDirect(1024);
    buf.position(buf.limit());
    while (true) {
      if (buf.remaining() < 8) {
        if (inChannel.read(buf.compact()) == -1) {
          break;
        }
        buf.flip();
      }
      int strLength = (int) buf.getDouble();
      if (buf.remaining() < 2 * strLength) {
        if (inChannel.read(buf.compact()) == -1) {
          break;
        }
        buf.flip();
      }
      byte[] strChars = new byte[2 * strLength];
      buf.get(strChars);
      if (buf.remaining() < 8) {
        if (inChannel.read(buf.compact()) == -1) {
          break;
        }
        buf.flip();
      }
      System.out.println(strLength);
      System.out.println(ByteBuffer.wrap(strChars).asCharBuffer());
      System.out.println(buf.getLong());
    }
    inFile.close();  }

}

   
    
    
  








Related examples in the same category

1.ByteBuffer: allocate(int capacity)
2.ByteBuffer: allocateDirect(int size)
3.ByteBuffer: asCharBuffer()
4.ByteBuffer: asDoubleBuffer()
5.ByteBuffer: asFloatBuffer()
6.ByteBuffer: asLongBuffer()
7.ByteBuffer: asShortBuffer()
8.ByteBuffer: capacity()
9.ByteBuffer: clear()
10.ByteBuffer: compact()
11.ByteBuffer: flip()
12.ByteBuffer: get()
13.ByteBuffer: get(byte[] dst, int offset, int length)
14.ByteBuffer: get(int index)
15.ByteBuffer: getChar()
16.ByteBuffer: getFloat()
17.ByteBuffer: getInt()
18.ByteBuffer: getLong()
19.ByteBuffer: isDirect()
20.ByteBuffer: limit()
21.ByteBuffer: order()
22.ByteBuffer: order(ByteOrder bo)
23.ByteBuffer: position()
24.ByteBuffer: position(int newPosition)
25.ByteBuffer: put(byte b)
26.ByteBuffer: putChar(char ch)
27.ByteBuffer: putDouble(double value)
28.ByteBuffer: putFloat(float value)
29.ByteBuffer: putInt(int i)
30.ByteBuffer: putLong(long value)
31.ByteBuffer: putShort(short value)
32.ByteBuffer: putShort(int index, short value)
33.ByteBuffer: rewind()
34.ByteBuffer: wrap(byte[] array)