Java Utililty Methods ByteBuffer Put

List of utility methods to do ByteBuffer Put

Description

The list of methods to do ByteBuffer Put are organized into topic(s).

Method

voidputString(@Nullable final String s, @Nonnull final ByteBuffer dst)
put String
if (s == null) {
    dst.putInt(-1);
    return;
final char[] array = s.toCharArray();
final int size = array.length;
dst.putInt(size);
for (int i = 0; i < size; i++) {
...
voidputString(ByteBuffer bb, String s)
put String
byte[] b = s.getBytes(Charset.forName("UTF-8"));
bb.putShort((short) b.length);
bb.put(b);
voidputString(ByteBuffer buf, String value)
put String
if (value == null) {
    buf.putShort((short) -1);
} else {
    buf.putShort((short) value.length()); 
    for (int i = 0; i < value.length(); i++) {
        buf.putChar(value.charAt(i));
voidputString(ByteBuffer buffer, String s)
Relative put operation.
Write a String in a ByteBuffer object.

In some case, you also need to put a NULL terminal character at the end of the string.
buffer.put(s.getBytes());
voidputString(ByteBuffer buffer, String s)
Relative put operation.
Write a String in a ByteBuffer object.

In some case, you also need to put a NULL terminal character at the end of the string.
buffer.put(s.getBytes());
voidputString(final ByteBuffer buffer, final String string)
Writes the given String to the ByteBuffer.
buffer.putInt(string.length());
for (int i = 0; i < string.length(); i++) {
    buffer.putChar(string.charAt(i));
voidputString(String name, ByteBuffer buffer)
put String
buffer.put(name.getBytes()).put((byte) 0);
ByteBufferputString(String str, ByteBuffer bb)
put String
if (str == null) {
    throw new NullPointerException("Argument str cannot be null");
if (bb == null) {
    throw new NullPointerException("Argument bb cannot be null");
if (str.length() > 255) {
    throw new IllegalArgumentException("Cannot store string: length greater than 255 characters.");
...
voidputStringAsCharArray(ByteBuffer byteBuffer, String s)
put String As Char Array
byteBuffer.asCharBuffer().put(s);
byteBuffer.position(byteBuffer.position() + (s.length() * 2));
voidputStringToByteBuffer(final ByteBuffer bb, String value, String charset)
put String To Byte Buffer
if (value != null) {
    try {
        bb.put(value.getBytes(charset));
    } catch (UnsupportedEncodingException e) {
        bb.put(value.getBytes());