Java ByteBuffer to String getString(java.nio.ByteBuffer buffer, int offset, int len)

Here you can find the source of getString(java.nio.ByteBuffer buffer, int offset, int len)

Description

get String

License

Open Source License

Declaration

public static String getString(java.nio.ByteBuffer buffer, int offset,
            int len) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getString(java.nio.ByteBuffer buffer, int offset,
            int len) {
        String s = "";
        if (null != buffer && buffer.capacity() >= offset + len) {
            byte[] dest = new byte[len];
            buffer.position(offset);/*from   w  w  w . ja  va  2s . c  o m*/
            buffer.get(dest, 0, len);
            s = new String(dest).trim();
        }
        return s;
    }

    public static String getString(java.nio.ByteBuffer buffer, int len) {
        String s = "";
        if (null != buffer && buffer.remaining() >= len) {
            byte[] dest = new byte[len];
            buffer.get(dest, 0, len);
            s = new String(dest).trim();
        }
        return s;
    }
}

Related

  1. getString(ByteBuffer buffer, String charFormat)
  2. getString(ByteBuffer byteBuffer, int size)
  3. getString(ByteBuffer in, int maxLength)
  4. getString(final ByteBuffer buffer)
  5. getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
  6. getStringA(ByteBuffer byteBuffer, int length)
  7. getStringDTrimmed(ByteBuffer byteBuffer, int length)
  8. getStringFromBuffer(ByteBuffer buf, int len)
  9. getStringFromBuffer(ByteBuffer buffer, int length)