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

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

Description

Produces a string prepresentation of the byte array.

License

Open Source License

Parameter

Parameter Description
b the array to be processed.

Return

A string representation of the byte array.

Declaration

public static String bytesToString(byte[] b) 

Method Source Code

//package com.java2s;
/*//from ww w .  j a  va 2 s.c o  m
 * $Id$
 * 
 * Copyright (c) 2008-2014 David Muller <roxon@users.sourceforge.net>.
 * All rights reserved. Use of the code is allowed under the
 * Artistic License 2.0 terms, as specified in the LICENSE file
 * distributed with this code, or available from
 * http://www.opensource.org/licenses/artistic-license-2.0.php
 */

public class Main {
    /**
     * Produces a string prepresentation of the byte array.
     * 
     * @param b the array to be processed.
     * 
     * @return A string representation of the byte array.
     */
    public static String bytesToString(byte[] b) {
        StringBuffer sb;

        sb = new StringBuffer();

        sb.append("{ ");
        for (int ii = 0; ii < b.length; ++ii) {
            if (ii > 0) {
                sb.append(", ");
            }
            sb.append(b[ii]);
        }
        sb.append(" }");

        return sb.toString();
    }
}

Related

  1. bytesToStr(byte[] input)
  2. bytesToStrHex(byte[] bytes)
  3. bytesToString(byte... bytes)
  4. bytesToString(byte[] arr)
  5. bytesToString(byte[] arr, int pos)
  6. bytesToString(byte[] buffer, int index, int length)
  7. bytesToString(byte[] bytes)
  8. bytesToString(byte[] bytes)
  9. bytesToString(byte[] bytes)