Here you can find the source of readString(ByteBuffer buff, int len)
Parameter | Description |
---|---|
buff | the source buffer |
len | the number of characters |
public static String readString(ByteBuffer buff, int len)
//package com.java2s; /*//from ww w . jav a2 s .c o m * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group */ import java.nio.ByteBuffer; public class Main { /** * Read a string. * * @param buff the source buffer * @param len the number of characters * @return the value */ public static String readString(ByteBuffer buff, int len) { char[] chars = new char[len]; for (int i = 0; i < len; i++) { int x = buff.get() & 0xff; if (x < 0x80) { chars[i] = (char) x; } else if (x >= 0xe0) { chars[i] = (char) (((x & 0xf) << 12) + ((buff.get() & 0x3f) << 6) + (buff.get() & 0x3f)); } else { chars[i] = (char) (((x & 0x1f) << 6) + (buff.get() & 0x3f)); } } return new String(chars); } }