Here you can find the source of putString(final ByteBuffer buffer, final String string)
Parameter | Description |
---|---|
buffer | a parameter |
string | a parameter |
public static void putString(final ByteBuffer buffer, final String string)
//package com.java2s; /* *********************************************************************** * * project: org.matsim.*//w w w .jav a 2 s . c om * 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 { /** * Writes the given String to the ByteBuffer. First writes the length of the String as int, * then writes the single characters. The ByteBuffer's position is incremented according * to the length of the String. * * @param buffer * @param string */ public static void putString(final ByteBuffer buffer, final String string) { buffer.putInt(string.length()); for (int i = 0; i < string.length(); i++) { buffer.putChar(string.charAt(i)); } } }