Here you can find the source of getString(ByteBuffer buffer, int offset, int length, String encoding)
Parameter | Description |
---|---|
buffer | a parameter |
offset | a parameter |
length | a parameter |
encoding | a parameter |
public static String getString(ByteBuffer buffer, int offset, int length, String encoding)
//package com.java2s; /*//from www . jav a 2s .c o m * Entagged Audio Tag library * Copyright (c) 2003-2005 Rapha?l Slinckx <raphael@slinckx.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.io.*; import java.nio.ByteBuffer; public class Main { /** * Create String starting from offset upto length using encoding * * @param b * @param offset * @param length * @param encoding * @return * @throws UnsupportedEncodingException */ public static String getString(byte[] b, int offset, int length, String encoding) { try { return new String(b, offset, length, encoding); } catch (UnsupportedEncodingException ue) { //Shouldnt have to worry about this exception as should only be calling with well defined charsets throw new RuntimeException(ue); } } /** * Create String offset from position by offset upto length using encoding, and position of buffer * is moved to after position + offset + length * * @param buffer * @param offset * @param length * @param encoding * @return */ public static String getString(ByteBuffer buffer, int offset, int length, String encoding) { byte[] b = new byte[length]; buffer.position(buffer.position() + offset); buffer.get(b); try { return new String(b, 0, length, encoding); } catch (UnsupportedEncodingException uee) { //TODO, will we ever use unsupported encodings throw new RuntimeException(uee); } } }