Java ByteBuffer Print println(String string, ByteBuffer buffer)

Here you can find the source of println(String string, ByteBuffer buffer)

Description

println

License

Apache License

Declaration

public static void println(String string, ByteBuffer buffer) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static void println(String string, ByteBuffer buffer) {
        if (buffer == null || !buffer.hasRemaining())
            return;
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);/*from  w ww  .  ja  va  2s  .  co m*/
        buffer.flip();
        println(string, bytes);
    }

    public static void println(String string, byte... bytes) {
        if (bytes == null)
            return;
        StringBuilder sb = new StringBuilder();
        if (string != null)
            sb.append(string);
        sb.append(bytes.length).append(".[");
        boolean last = false;
        for (byte b : bytes) {
            if (last)
                sb.append(',');
            int v = b & 0xff;
            if (v < 16)
                sb.append('0');
            sb.append(Integer.toHexString(v));
            last = true;
        }
        sb.append(']');
        (System.out).println(sb);
    }
}

Related

  1. printBuffer(String msg, ByteBuffer buffer)
  2. printByteBuffer(ByteBuffer buf)
  3. printData(ByteBuffer buf, int offset, int len)
  4. printData(ByteBuffer buffer, int len)
  5. printImageContentsSubset(ByteBuffer buf, int w, int h)
  6. printTraceHexData(PrintWriter trc, ByteBuffer buf, int startPos, int endPos)