Example usage for java.nio LongBuffer put

List of usage examples for java.nio LongBuffer put

Introduction

In this page you can find the example usage for java.nio LongBuffer put.

Prototype

public LongBuffer put(LongBuffer src) 

Source Link

Document

Writes all the remaining longs of the src long buffer to this buffer's current position, and increases both buffers' position by the number of longs copied.

Usage

From source file:Main.java

public static void main(String[] args) {
    LongBuffer bb = LongBuffer.allocate(10);
    bb.put(100L);

    bb.rewind();//from   www  .  j ava 2  s .  co  m

    LongBuffer longBuffer2 = LongBuffer.allocate(10);

    longBuffer2.put(bb);

    System.out.println(Arrays.toString(longBuffer2.array()));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);

    longBuffer.rewind();//ww  w. j  a v  a2s  .  c  o  m

    LongBuffer longBuffer2 = longBuffer.compact();

    System.out.println(Arrays.toString(longBuffer2.array()));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);

    longBuffer.rewind();//from   w  ww  . j a v  a2 s .c o  m

    LongBuffer longBuffer2 = longBuffer.asReadOnlyBuffer();

    System.out.println(Arrays.toString(longBuffer2.array()));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);

    longBuffer.rewind();//from   w  w  w  . ja v a  2  s  . c o  m

    LongBuffer longBuffer2 = longBuffer.compact();

    System.out.println(longBuffer2.compareTo(longBuffer2));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);

    longBuffer.rewind();/*from   w  w w. java  2s .  c om*/

    LongBuffer longBuffer2 = longBuffer.slice();

    System.out.println(longBuffer2.equals(longBuffer2));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer longBuffer = LongBuffer.allocate(10);
    longBuffer.put(100);

    longBuffer.rewind();/* w w w  .ja v  a 2s.co  m*/

    LongBuffer longBuffer2 = longBuffer.duplicate();

    System.out.println(longBuffer2.equals(longBuffer2));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer bb = LongBuffer.wrap(new long[] { 0, 1, 2, 3, 4, 5, 6 });
    bb.put(100);
    System.out.println(Arrays.toString(bb.array()));

}

From source file:Main.java

public static void main(String[] args) {
    LongBuffer bb = LongBuffer.wrap(new long[] { 0, 1, 2, 3, 4, 5, 6 }, 0, 3);
    bb.put(100L);
    System.out.println(Arrays.toString(bb.array()));

}

From source file:MainClass.java

public static void main(String[] args) {
    long[] primes = new long[] { 1, 2, 3, 5, 7 };
    File aFile = new File("C:/test/primes.txt");
    FileOutputStream outputFile = null;
    try {/* www  .j  ava 2s.c o m*/
        outputFile = new FileOutputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel file = outputFile.getChannel();
    final int BUFFERSIZE = 100;
    ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE);
    DoubleBuffer doubleBuf = buf.asDoubleBuffer();
    buf.position(8);
    CharBuffer charBuf = buf.asCharBuffer();
    for (long prime : primes) {
        String primeStr = "prime = " + prime;
        doubleBuf.put(0, (double) primeStr.length());
        charBuf.put(primeStr);
        buf.position(2 * charBuf.position() + 8);
        LongBuffer longBuf = buf.asLongBuffer();
        longBuf.put(prime);
        buf.position(buf.position() + 8);
        buf.flip();
        try {
            file.write(buf);
        } catch (IOException e) {
            e.printStackTrace(System.err);
        }
        buf.clear();
        doubleBuf.clear();
        charBuf.clear();
    }
    try {
        System.out.println("File written is " + file.size() + "bytes.");
        outputFile.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:org.bimserver.utils.BinUtils.java

public static byte[] longToByteArray(long inLong) {
    byte[] bArray = new byte[8];
    ByteBuffer bBuffer = ByteBuffer.wrap(bArray);
    LongBuffer lBuffer = bBuffer.asLongBuffer();
    lBuffer.put(inLong);
    return bArray;
}