Java ByteBuffer Append appendHex(StringBuilder sb, ByteBuffer bb)

Here you can find the source of appendHex(StringBuilder sb, ByteBuffer bb)

Description

append Hex

License

Open Source License

Declaration

public static StringBuilder appendHex(StringBuilder sb, ByteBuffer bb) 

Method Source Code


//package com.java2s;
/*/*  w ww .  jav a 2  s  .  c  om*/
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2007, 2009, 2010, 2011, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.nio.ByteBuffer;

public class Main {
    public static StringBuilder appendHex(StringBuilder sb, ByteBuffer bb) {
        int limit = bb.limit();
        for (int i = bb.position(); i < limit; i++) {
            int c = bb.get(i) & 0xff;
            sb.append(Character.forDigit(c >> 4, 16));
            sb.append(Character.forDigit(c & 0xf, 16));
            if (i < limit - 1)
                sb.append(' ');
        }
        return sb;
    }
}

Related

  1. append(ByteBuffer buffer, String s)
  2. append(ByteBuffer source, int index, byte[] dest)
  3. append(ByteBuffer to, byte[] b, int off, int len)
  4. appendBuffers(ByteBuffer buffer, ByteBuffer buffer1, int incomingBufferSize, int BUFFER_STEP_SIZE)
  5. appendLong(long value, ByteBuffer buffer)
  6. appendOrRealloc(ByteBuffer dest, ByteBuffer toAppend)
  7. appendSurrogate(ByteBuffer bb, char c)
  8. appendToByteBuffer(ByteBuffer bb, byte[] bytes, int len)