Java ByteBuffer to String getString(ByteBuffer buffer, int length)

Here you can find the source of getString(ByteBuffer buffer, int length)

Description

get String

License

Open Source License

Parameter

Parameter Description
buffer a parameter
length a parameter

Declaration

public static String getString(ByteBuffer buffer, int length) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**/* w w w.j av  a2  s. c om*/
     * 
     * @param buffer
     * @param length
     * @return
     */
    public static String getString(ByteBuffer buffer, int length) {
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < length; i++) {
            builder.append((char) buffer.get());
        }

        return builder.toString();
    }
}

Related

  1. getString(ByteBuffer buf)
  2. getString(ByteBuffer buf, Charset encoding)
  3. getString(ByteBuffer buf, int length, String charsetName)
  4. getString(ByteBuffer buffer)
  5. getString(ByteBuffer buffer)
  6. getString(ByteBuffer buffer, int offset, int length, String encoding)
  7. getString(ByteBuffer buffer, int size)
  8. getString(ByteBuffer buffer, int size)
  9. getString(ByteBuffer buffer, String charFormat)