Example usage for java.nio ByteBuffer array

List of usage examples for java.nio ByteBuffer array

Introduction

In this page you can find the example usage for java.nio ByteBuffer array.

Prototype

public final byte[] array() 

Source Link

Document

Returns the byte array which this buffer is based on, if there is one.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.putShort(2, (short) 123);

    ByteBuffer bb = bbuf.slice();

    System.out.println(Arrays.toString(bb.array()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.putShort(2, (short) 123);

    ByteBuffer bb = bbuf.compact();

    System.out.println(Arrays.toString(bb.array()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.putShort(2, (short) 123);

    ByteBuffer bb = bbuf.duplicate();

    System.out.println(Arrays.toString(bb.array()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    byte[] bytes = new byte[10];
    ByteBuffer buf = ByteBuffer.wrap(bytes);

    System.out.println(Arrays.toString(buf.array()));
    System.out.println(buf.toString());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    byte[] bytes = new byte[10];
    ByteBuffer buf = ByteBuffer.wrap(bytes, 0, 4);

    System.out.println(Arrays.toString(buf.array()));
    System.out.println(buf.toString());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    int capacity = bbuf.capacity(); // 10
    System.out.println(capacity);
    bbuf.put("java2s.com".getBytes(), 0, 2);

    ByteBuffer bbuf1 = ByteBuffer.allocate(10);
    bbuf1.put(bbuf);//from   ww w. jav  a 2s . c o  m
    System.out.println(Arrays.toString(bbuf1.array()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    byte[] bytes = new byte[10];
    ByteBuffer buf = ByteBuffer.allocate(10);
    buf = ByteBuffer.wrap(bytes);

    System.out.println(Arrays.toString(buf.array()));
    System.out.println(buf.toString());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    byte[] bytes = new byte[10];
    ByteBuffer buf = ByteBuffer.allocateDirect(10);
    buf = ByteBuffer.wrap(bytes);

    System.out.println(Arrays.toString(buf.array()));
    System.out.println(buf.toString());
}

From source file:MainClass.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[12]);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));
    bb.rewind();/*from   w w  w .j  a v a2 s . c  o  m*/
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));
    bb.rewind();
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));
}

From source file:Endians.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[12]);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));
    bb.rewind();//from  w  w  w  . j  a v  a 2  s . c  o  m
    bb.order(ByteOrder.BIG_ENDIAN);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));
    bb.rewind();
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.asCharBuffer().put("abcdef");
    System.out.println(toString(bb.array()));

}