Example usage for java.nio ByteBuffer asCharBuffer

List of usage examples for java.nio ByteBuffer asCharBuffer

Introduction

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

Prototype

public abstract CharBuffer asCharBuffer();

Source Link

Document

Returns a char buffer which is based on the remaining content of this byte buffer.

Usage

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("java2s.com");
    char c = bb.getChar(1);
    System.out.print(c + " ");

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("Howdy!");
    char c;// ww  w  . jav a2s  .  co m
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("java2s.com");
    char c;// www. j a  va2 s.c  o m
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("java2s!");
    byte[] dst = new byte[BSIZE];
    bb.rewind();//w  ww  .jav  a 2 s .  com
    bb.get(dst, 0, 3);
    System.out.println(Arrays.toString(dst));

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("java2s!");
    bb.rewind();// w ww. j a v  a  2s.  c  o  m
    byte[] dst = new byte[BSIZE];
    bb.get(dst);
    System.out.println(Arrays.toString(dst));

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("java2s.com");
    bb.rewind();/*from   w w  w  .  j  a  v  a  2 s  .  com*/
    char c;
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();

}

From source file:Main.java

public static void main(String[] args) {
    ByteBuffer bb = ByteBuffer.allocate(BSIZE);
    bb.asCharBuffer().put("Howdy!");
    char c;//w  w w. j a v  a2  s  .  c o m
    while ((c = bb.getChar()) != 0)
        System.out.print(c + " ");
    System.out.println();

    bb.rewind();
    // Store and read a short:
    bb.asShortBuffer().put((short) 471142);
    System.out.println(bb.getShort());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(15);

    CharBuffer cbuf = buf.asCharBuffer();

}

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  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()));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(100);

    CharBuffer cbuf = buf.asCharBuffer();

    cbuf.put("a string");

    int start = 2; // start is relative to cbuf's current position
    int end = 5;//from w  ww  .j  av a2 s.  c  o m
    CharSequence sub = cbuf.subSequence(start, end); // str

}