Java Byte Array Create toByteString(byte[] content, int len)

Here you can find the source of toByteString(byte[] content, int len)

Description

to Byte String

License

Apache License

Declaration

public static String toByteString(byte[] content, int len) 

Method Source Code

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

public class Main {
    public static String toByteString(byte[] content, int len) {
        if (content == null || content.length == 0) {
            return "";
        }//  w w w  .  j  a  v  a2s .  c  om
        if (len > content.length) {
            len = content.length;
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int c = content[i];
            c &= 0xFF;
            sb.append((char) c);
        }
        return sb.toString();
    }

    public static String toByteString(byte[] content) {
        if (content == null) {
            return "";
        }
        return toByteString(content, content.length);
    }
}

Related

  1. toBytesLittleEndian(long value, int cnt)
  2. toBytesOctalEscaped(final byte[] s, final int off, final int len)
  3. toBytesShortBE(short w)
  4. toBytesString(byte[] bytes)
  5. toByteString(byte[] bytes, String seperator)
  6. toByteString(final byte[] b)
  7. toByteString(final String source)
  8. toBytesWithLength(byte[] buffer, int pos, String string)
  9. toBytesWithLengthLong(byte[] buffer, int pos, byte[] bytes)