Java ByteBuffer to String toString(@Nonnull ByteBuffer buf, int len)

Here you can find the source of toString(@Nonnull ByteBuffer buf, int len)

Description

to String

License

Apache License

Declaration

@Nonnull
    public static String toString(@Nonnull ByteBuffer buf, int len) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

import java.util.Arrays;

import javax.annotation.Nonnull;

public class Main {
    @Nonnull
    public static String toString(@Nonnull ByteBuffer buf, int len) {
        byte[] b = new byte[Math.min(buf.remaining(), len)];
        for (int i = 0; i < b.length; i++)
            b[i] = buf.get(buf.position() + i);
        return "[" + Arrays.toString(b) + "...(" + buf.remaining() + " bytes)]";
    }//  w w  w . j av a 2s  .c  o m
}

Related

  1. string(ByteBuffer b, Charset charset)
  2. string(ByteBuffer buffer)
  3. string(ByteBuffer buffer)
  4. string(ByteBuffer buffer, int position, int length, Charset charset)
  5. string(ByteBuffer bytes)
  6. toString(ByteBuffer b, String separator)
  7. toString(ByteBuffer bb)
  8. toString(ByteBuffer buf)
  9. toString(ByteBuffer buf, int len)