Java ByteBuffer Write writeUTF8StringToByteBuffer(String str, ByteBuffer bb)

Here you can find the source of writeUTF8StringToByteBuffer(String str, ByteBuffer bb)

Description

write UTF String To Byte Buffer

License

Open Source License

Declaration

public static void writeUTF8StringToByteBuffer(String str, ByteBuffer bb) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.*;
import java.nio.charset.*;

public class Main {
    public static void writeUTF8StringToByteBuffer(String str, ByteBuffer bb) {
        Charset charset = Charset.forName("UTF-8");
        CharsetEncoder encoder = charset.newEncoder();
        CharBuffer in = CharBuffer.wrap(str);
        try {/*from w  w w. j a  v a 2s  . c  o  m*/
            encoder.encode(in, bb, true);
            return;
        } catch (Exception e) {
            e.printStackTrace();
        }
        bb = null;
        return;
    }
}

Related

  1. writeUB2(ByteBuffer buffer, int i)
  2. writeUnsigned(int num, int size, ByteBuffer out)
  3. writeUnsignedInt(ByteBuffer buf, long value)
  4. writeUnsignedInt(final ByteBuffer buffer, final long value)
  5. writeUnsignedVarInt(int value, ByteBuffer dest)
  6. writeUUID(ByteBuffer buffer, UUID uuid)
  7. writeV(ByteBuffer byteBuffer, List vint)
  8. writeVarint(int value, ByteBuffer buffer)
  9. writeVarLong(ByteBuffer buff, long x)