Java ByteBuffer Put putStr(ByteBuffer buff, String str)

Here you can find the source of putStr(ByteBuffer buff, String str)

Description

write a String to a ByteBuffer, prepended with a short integer representing the length of the String

License

Open Source License

Declaration

public static void putStr(ByteBuffer buff, String str) 

Method Source Code


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

import java.nio.*;

public class Main {
    /**/*w ww.  j  a  v  a2 s.  co  m*/
     * write a String to a ByteBuffer,
     * prepended with a short integer representing the length of the String
     */
    public static void putStr(ByteBuffer buff, String str) {
        if (str == null) {
            buff.putShort((short) 0);
        } else {
            buff.putShort((short) str.length());
            buff.put(str.getBytes());
        }
    }
}

Related

  1. putObject(ByteBuffer byteBuffer, Object object)
  2. putObject(final ByteBuffer buffer, Serializable o)
  3. putQuickchatParam(ByteBuffer buf, long param, int size)
  4. putRange(ByteBuffer buffer, int start, int end, byte b)
  5. putRGBfromHSB(final ByteBuffer pixels, final float[] hsb, int pixelSize)
  6. putString(@Nullable final String s, @Nonnull final ByteBuffer dst)
  7. putString(ByteBuffer bb, String s)
  8. putString(ByteBuffer buf, String value)
  9. putString(ByteBuffer buffer, String s)