Java ByteBuffer Read readCharsUTF8(ByteBuffer bb, int length)

Here you can find the source of readCharsUTF8(ByteBuffer bb, int length)

Description

read Chars UTF

License

LGPL

Declaration

public static String readCharsUTF8(ByteBuffer bb, int length)
            throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.IOException;
import java.nio.ByteBuffer;

public class Main {
    private static final String CHARSET_UTF8 = "UTF-8";

    public static String readCharsUTF8(ByteBuffer bb, int length)
            throws IOException {
        byte[] b = new byte[length];
        bb.get(b);/*from   w  w  w  .j  a v  a  2s . c  o m*/

        // lookup null character for string termination
        int strLength = 0;
        for (int i = 0; i < b.length; i++) {
            if (b[i] == 0) {
                break;
            }
            strLength++;
        }

        return new String(b, 0, strLength, CHARSET_UTF8);
    }
}

Related

  1. readBuffer(ByteChannel channel, ByteBuffer buffer)
  2. readBufferFully(FileChannel fc, ByteBuffer buf, int startPos)
  3. readByteBuffer(ByteBuffer buf)
  4. readByteBufferFromFile(String filepath)
  5. readChars(ByteBuffer bb, int length)
  6. readCInt(ByteBuffer buffer)
  7. readCString(ByteBuffer buf, int len)
  8. readDERString(ByteBuffer buf)
  9. readDword(ByteBuffer buffer)