Here you can find the source of getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
Parameter | Description |
---|---|
buffer | a parameter |
offset | offset from current position |
length | size of data to process |
encoding | a parameter |
public static String getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
//package com.java2s; /*// w w w.j av a 2 s .c om * 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.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { /** * Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet. * * @param buffer * @param offset offset from current position * @param length size of data to process * @param encoding * @return */ public static String getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding) { final byte[] b = new byte[length]; buffer.position(buffer.position() + offset); buffer.get(b); return new String(b, 0, length, encoding); } /** * Reads bytes from a ByteBuffer as if they were encoded in the specified CharSet. * * @param buffer * @param encoding * @return */ public static String getString(final ByteBuffer buffer, final Charset encoding) { final byte[] b = new byte[buffer.remaining()]; buffer.get(b); return new String(b, 0, b.length, encoding); } }