Java ByteBuffer to String getStr(ByteBuffer buff)

Here you can find the source of getStr(ByteBuffer buff)

Description

read a String from a ByteBuffer that was written w/the putStr method

License

Open Source License

Declaration

public static String getStr(ByteBuffer buff) 

Method Source Code


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

import java.nio.*;

public class Main {
    /**/*from   w w w  .  j ava  2s  .  c o  m*/
     * read a String from a ByteBuffer
     * that was written w/the putStr method
     */
    public static String getStr(ByteBuffer buff) {
        short len = buff.getShort();
        if (len == 0) {
            return null;
        } else {
            byte[] b = new byte[len];
            buff.get(b);
            return new String(b);
        }
    }
}

Related

  1. bytesToString(ByteBuffer buf, int off, int len)
  2. convertBufferToString(ByteBuffer buffer)
  3. decodeString(ByteBuffer bb)
  4. decodeString(ByteBuffer buffer, String charset)
  5. decodeString(ByteBuffer src)
  6. getString(@Nonnull final ByteBuffer src)
  7. getString(ByteBuffer bb)
  8. getString(ByteBuffer buf)
  9. getString(ByteBuffer buf)