Example usage for java.nio CharBuffer put

List of usage examples for java.nio CharBuffer put

Introduction

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

Prototype

public final CharBuffer put(String str) 

Source Link

Document

Writes all chars of the given string to the current position of this buffer, and increases the position by the length of string.

Usage

From source file:Main.java

public static void main(String[] args) {
    CharBuffer cb1 = CharBuffer.allocate(5);
    cb1.put(new char[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm', });
    cb1.rewind();//  w ww  .  j  a  v a  2  s. c om

    System.out.println(cb1.toString());
}

From source file:Main.java

public static void main(String[] args) {
    CharBuffer cb1 = CharBuffer.allocate(5);
    cb1.put("java2s.com");
    cb1.rewind();/*  w ww .  java 2 s. c  om*/

    System.out.println(cb1.toString());
}

From source file:Main.java

public static void main(String[] args) {
    CharBuffer cb1 = CharBuffer.allocate(5);
    cb1.put('j').put('a').put('v').put('a').put('2').put('s');
    ;/*from  w w  w  .  ja v a2s  . c om*/
    cb1.rewind();

    System.out.println(cb1.toString());
}

From source file:Main.java

public static void main(String[] args) {
    CharBuffer cb1 = CharBuffer.allocate(5);
    cb1.put(new char[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm', });
    cb1.rewind();/*from   ww  w .  j av a  2s  .  c  o m*/

    CharBuffer cb2 = CharBuffer.allocate(5);
    cb2.put(cb1);
    System.out.println(cb2.toString());
}

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;/*  w w w.  j av a 2  s .co m*/
    CharSequence sub = cbuf.subSequence(start, end); // str

}

From source file:MainClass.java

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

    cb.put("This is a test String");

    cb.flip();/*from   w w w .j  av a  2s  .  com*/

    // This throws an IllegalArgumentException
    cb.put(cb);

    System.out.println(cb);
}

From source file:Main.java

public static void main(String[] args) {
    char[] data = "UsingBuffers".toCharArray();
    ByteBuffer bb = ByteBuffer.allocate(data.length * 2);
    CharBuffer cb = bb.asCharBuffer();
    cb.put(data);
    System.out.println(cb.rewind());
    symmetricScramble(cb);/*from w  w w  .j  a  va 2  s  . co  m*/
    System.out.println(cb.rewind());
    symmetricScramble(cb);
    System.out.println(cb.rewind());

}

From source file:MainClass.java

public static void main(String[] args) {
    char[] data = "UsingBuffers".toCharArray();
    ByteBuffer bb = ByteBuffer.allocate(data.length * 2);
    CharBuffer cb = bb.asCharBuffer();
    cb.put(data);
    System.out.println(cb.rewind());
    symmetricScramble(cb);//from w ww .j a  v a  2s.  c om
    System.out.println(cb.rewind());
    symmetricScramble(cb);
    System.out.println(cb.rewind());
}

From source file:MainClass.java

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

    cb.put("Hello World");
    println(cb);//from ww w.  java  2 s  .c  o m

    cb.flip();
    println(cb);

    cb.flip();
    println(cb);
}

From source file:Main.java

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

    cb.put("This is a test String");

    cb.flip();//from   w w  w .j ava 2s.c  om

    System.out.println("hasArray() = " + cb.hasArray());

    char[] carray = cb.array();

    System.out.print("array=");

    for (int i = 0; i < carray.length; i++) {
        System.out.print(carray[i]);
    }

}