Java ByteBuffer Write writeString(ByteBuffer byteBuffer, String str)

Here you can find the source of writeString(ByteBuffer byteBuffer, String str)

Description

write String

License

Open Source License

Declaration

public static void writeString(ByteBuffer byteBuffer, String str) 

Method Source Code


//package com.java2s;
/*/*from w w w  . j a v  a  2 s.co m*/
 * (C) 2007-2010 Alibaba Group Holding Limited.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

import java.nio.ByteBuffer;

public class Main {
    public static void writeString(ByteBuffer byteBuffer, String str) {
        if (str == null) {
            byteBuffer.putInt(0);
        } else {
            byte[] b = str.getBytes();

            byteBuffer.putInt(b.length + 1);
            byteBuffer.put(b);
            byteBuffer.put((byte) 0);
        }
    }
}

Related

  1. writeSlice(ByteBuffer src, int number, ByteBuffer dst)
  2. writeString(ByteBuffer buf, String s)
  3. writeString(ByteBuffer buf, String str)
  4. writeString(ByteBuffer buf, String value)
  5. writeString(ByteBuffer buffer, String string)
  6. writeString(final String text, final ByteBuffer out)
  7. writeString(String s, ByteBuffer buff)
  8. writeString(String string, ByteBuffer bb)
  9. writeStringArray(ByteBuffer buf, String[] array)