Java Byte Array to String bytesToString(byte[] id)

Here you can find the source of bytesToString(byte[] id)

Description

Returns a string representation of any part of transaction id.

License

Open Source License

Parameter

Parameter Description
id some part of transaction id

Return

string representation

Declaration

private static String bytesToString(byte[] id) 

Method Source Code

//package com.java2s;
/**//from  ww w . j  av  a2s.  c  om
 * Copyright 2015 Pozna? Supercomputing and Networking Center
 *
 * Licensed under the GNU General Public License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Hexadecimal digits.
     */
    private static final String HEX_DIGITS = "0123456789ABCDEF";

    /**
     * Returns a string representation of any part of transaction id.
     * 
     * @param id
     *            some part of transaction id
     * @return string representation
     */
    private static String bytesToString(byte[] id) {
        StringBuffer sb = new StringBuffer(128);
        int value;
        for (byte b : id) {
            value = b & 0xff;
            sb.append(HEX_DIGITS.charAt(value / 16));
            sb.append(HEX_DIGITS.charAt(value & 15));
        }
        return sb.toString();
    }
}

Related

  1. bytesToString(byte[] bytes, int startIndex)
  2. bytesToString(byte[] bytes, String encoding)
  3. bytesToString(byte[] data)
  4. bytesToString(byte[] data, int start, int end)
  5. bytesToString(byte[] hasher)
  6. bytesToString(byte[] input)
  7. bytesToString(byte[] myByte)
  8. bytesToString(byte[] value)
  9. bytesToString(char[] bytes, boolean le, boolean signed)