Java ByteBuffer to String readString(ByteBuffer byteBuffer)

Here you can find the source of readString(ByteBuffer byteBuffer)

Description

read String

License

Open Source License

Declaration

public static String readString(ByteBuffer byteBuffer) 

Method Source Code


//package com.java2s;
/*//  www  .  ja va2 s.  c  o 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 String readString(ByteBuffer byteBuffer) {
        int len = byteBuffer.getInt();

        if (len <= 1) {
            return "";
        } else {
            byte[] b = new byte[len];

            byteBuffer.get(b);
            return new String(b, 0, len - 1);
        }
    }
}

Related

  1. readString(ByteBuffer buff)
  2. readString(ByteBuffer buff, int len)
  3. readString(ByteBuffer buffer)
  4. readString(ByteBuffer buffer)
  5. readString(ByteBuffer byteBuffer)
  6. readString(ByteBuffer logBuf)
  7. readString(final ByteBuffer buffer, final String encoding)
  8. string(ByteBuffer b, Charset charset)
  9. string(ByteBuffer buffer)