Here you can find the source of getString(final ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | a parameter |
public static String getString(final ByteBuffer buffer)
//package com.java2s; /* *********************************************************************** * * project: org.matsim.*/*from w w w. ja v a2 s .co m*/ * ByteBufferUtils.java * * * *********************************************************************** * * * * copyright : (C) 2009 by the members listed in the COPYING, * * LICENSE and WARRANTY file. * * email : info at matsim dot org * * * * *********************************************************************** * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * See also COPYING, LICENSE and WARRANTY file * * * * *********************************************************************** */ import java.nio.ByteBuffer; public class Main { /** * Reads a String from a ByteBuffer. Reads first an int for the length of the String, * and then the corresponding number of characters. Increments the position of the * ByteBuffer according to the length of the String. * * @param buffer * @return the String at the buffer's current position */ public static String getString(final ByteBuffer buffer) { int length = buffer.getInt(); char[] chBuffer = new char[length]; for (int i = 0; i < length; i++) { chBuffer[i] = buffer.getChar(); } return new String(chBuffer); } }