converts a byte array to printable characters

@param b - byte array
@return String representation
774879
public static String dumpString(byte[] b) {
    StringBuilder d = new StringBuilder(b.length * 2);
    for (byte aB : b) {
      char c = (char) aB;
      if (Character.isISOControl(c)) {
        switch (c) {
          case '\r':
            d.append("{CR}");
            break;
          case '\n':
            d.append("{LF}");
            break;
          case '\000':
            d.append("{NULL}");
            break;
          default:
            char hi = Character.forDigit((aB >> 4) & 0x0F, 16);
            char lo = Character.forDigit(aB & 0x0F, 16);
            d.append('[').append(Character.toUpperCase(hi)).append(Character.toUpperCase(lo)).append(']');
            break;
        }
      } else
        d.append(c);

    }
    return d.toString();
  }
1000724
public static String bytesToHexString(byte[] b) {
		StringBuffer sb = new StringBuffer();
		String hex;
		for (int i = 0; i < b.length; i++) {
			hex = Integer.toHexString(b[i] & 0xff);
			if (hex.length() == 1) {
				hex = '0' + hex;
			}
			sb.append(hex.toUpperCase());
		}
		return sb.toString();
	}
1304494
static String toHexString(final byte[] b) {
		StringBuffer sb = new StringBuffer("{");
		for (int i = 0; i < b.length; i++) {
			sb.append(toHexString(b[i]));
			if (i < b.length - 1) {
				sb.append(",");
			}
		}
		sb.append("}");
		return sb.toString();
	}
342290
public static String byteArrayToSQLBitString(byte[] bytes, int bitCount) {

        char[] s = new char[bitCount + 3];

        s[0] = 'B';
        s[1] = '\'';

        int pos = 2;

        for (int j = 0; j < bitCount; j++) {
            byte b = bytes[j / 8];

            s[pos++] = BitMap.isSet(b, j % 8) ? '1'
                                              : '0';
        }

        s[pos] = '\'';

        return new String(s);
    }
1044489
public static String byteToHex(byte b[]) {

        int    len = b.length;
        char[] s   = new char[len * 2];

        for (int i = 0, j = 0; i < len; i++) {
            int c = ((int) b[i]) & 0xff;

            s[j++] = HEXCHAR[c >> 4 & 0xf];
            s[j++] = HEXCHAR[c & 0xf];
        }

        return new String(s);
    }
910622
private static String byteArrayToHexString(byte[] b)
	{
		StringBuilder sb = new StringBuilder(b.length * 2);
		for (int i = 0; i < b.length; i++)
		{
			int v = b[i] & 0xff;
			if (v < 16)
			{
				sb.append('0');
			}
			sb.append(Integer.toHexString(v));
		}
		return sb.toString().toUpperCase();
	}
627170
public static String bytes2String(byte[] bytes) {
    try {
      final int len = bytes.length;
      char[] charArray = UTF8.getCharArray(len);
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] < UTF8.MIN_ASCII_CODE) {
          // non-ASCII codepoints' higher bytes
          // are of the form (10xxxxxx), hence the bytes
          // represent a non-ASCII string
          // do expensive conversion
          return new String(bytes, utf8charsetName);
        }
        // copy to temporary array
        charArray[i] = (char) bytes[i];
      }
      // only ASCII bytes, do fast conversion
      // using bytes as actual characters
      return new String(charArray, 0, len);
    } catch (UnsupportedEncodingException e) {
      assert false : "UTF8 encoding is not supported ";
    }
    return null;
  }
655290
public static String rawStringFromBytes(byte[] data) {
		StringBuilder str = new StringBuilder(data.length);
		for (byte b : data) {
			str.append((char) (b & 0xff));
		}
		return str.toString();
	}
182057
private static String byteArrayToHexString(byte[] byteArray) {
		StringBuilder result = new StringBuilder();
		
		for (byte b : byteArray) {
			result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
		}
		
		return result.toString();
	}
339896
public static String toStringBinary(final byte [] b, int off, int len) {
    StringBuilder result = new StringBuilder();
    try {
      String first = new String(b, off, len, "ISO-8859-1");
      for (int i = 0; i < first.length(); ++i) {
        int ch = first.charAt(i) & 0xFF;
        if ((ch >= '0' && ch <= '9')
            || (ch >= 'A' && ch <= 'Z')
            || (ch >= 'a' && ch <= 'z')
            || " `~!@#$%^&*()-_=+[]{}\\|;:'\",.<>/?".indexOf(ch) >= 0) {
          result.append(first.charAt(i));
        } else {
          result.append(String.format("\\x%02X", ch));
        }
      }
    } catch (UnsupportedEncodingException e) {
    }
    return result.toString();
  }
1149757
public static byte[] toByteArray(final ByteString bs) {
    return bs == null || bs.isEmpty() ? null : bs.toByteArray();
  }
261067
private static String getHexString(byte[] bytes) {

        // If null byte array given, return null
        if (bytes == null)
            return null;

        // Create string builder for holding the hex representation,
        // pre-calculating the exact length
        StringBuilder hex = new StringBuilder(2 * bytes.length);

        // Convert each byte into a pair of hex digits
        for (byte b : bytes) {
            hex.append(HEX_CHARS[(b & 0xF0) >> 4])
               .append(HEX_CHARS[ b & 0x0F      ]);
        }

        // Return the string produced
        return hex.toString();

    }
638693
public static String toHex(byte[] b) {
        char[] buf = new char[b.length * 2];
        int j = 0;
        int k;

        for (byte aB : b) {
            k = aB;
            buf[j++] = HEX[(k >>> 4) & 0x0F];
            buf[j++] = HEX[k & 0x0F];
        }
        return new String(buf);
    }
893090
public static String byteArrayToString(byte[] b) {
       final int l = b.length/2;
       if (l*2 != b.length) throw new IllegalArgumentException();
       StringBuffer result = new StringBuffer(l);
       int o = 0;
       for (int i = 0; i < l; i++)
       {
           int i1 = b[o++] & 0xff;
           int i2 = b[o++] & 0xff;
           i2 = i2 << 8;
           i1 = i1 | i2;
           result.append((char)i1);
       }
       return (result.toString());
    }
237292
public static String toHexString(byte[] b) {
        if (b == null)
            return null;

        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            int v = b[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                sb.append(0);
            }
            sb.append(hv);
        }
        return sb.toString();
    }
1074541
public static String encode(byte[] bytes) {
		int bytesLength = bytes.length;
		int base64Length = (bytesLength * 4 + 2) / 3; // base64 encoded string length, without padding

		StringBuilder base64Builder = new StringBuilder();
		int bytesIndex = 0;

		while (bytesIndex < bytesLength) {
			int i0 = bytes[bytesIndex++] & 0xff;
			int i1 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;
			int i2 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;

			int o0 = i0 >>> 2;
			int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
			int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
			int o3 = i2 & 0x3F;

			base64Builder.append(NIBLES_2_CHARS[o0]);
			base64Builder.append(NIBLES_2_CHARS[o1]);
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o2] : '=');
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o3] : '=');
		}

		return base64Builder.toString();
	}
151531
public static String getHexString( byte[] bytes ) {
        try {
            byte[] hex = new byte[2 * bytes.length];
            int index = 0;

            for (byte b : bytes) {
                int v = b & 0xFF;
                hex[index++] = HEX_CHAR_TABLE[v >>> 4];
                hex[index++] = HEX_CHAR_TABLE[v & 0xF];
            }
            return new String(hex, "ASCII");
        } catch (UnsupportedEncodingException e) {
            BigInteger bi = new BigInteger(1, bytes);
            return String.format("%0" + (bytes.length << 1) + "x", bi);
        }
    }