Java ByteBuffer Put putString(final ByteBuffer buffer, final String string)

Here you can find the source of putString(final ByteBuffer buffer, final String string)

Description

Writes the given String to the ByteBuffer.

License

Open Source License

Parameter

Parameter Description
buffer a parameter
string a parameter

Declaration

public static void putString(final ByteBuffer buffer, final String string) 

Method Source Code

//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));
        }
    }
}

Related

  1. putString(@Nullable final String s, @Nonnull final ByteBuffer dst)
  2. putString(ByteBuffer bb, String s)
  3. putString(ByteBuffer buf, String value)
  4. putString(ByteBuffer buffer, String s)
  5. putString(ByteBuffer buffer, String s)
  6. putString(String name, ByteBuffer buffer)
  7. putString(String str, ByteBuffer bb)
  8. putStringAsCharArray(ByteBuffer byteBuffer, String s)
  9. putStringToByteBuffer(final ByteBuffer bb, String value, String charset)