Write a printable representation of a byte array. Non-printable
characters are hex escaped in the format \\x%02X, eg:
\x00 \x05 etc

@param b array to write out
@param off offset to start at
@param len length to write
@return string output
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();
  }
227154
protected static String byteToHexString(byte ib) {
		char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
		char[] ob = new char[2];
		ob[0] = Digit[(ib >>> 4) & 0X0f];
		ob[1] = Digit[ib & 0X0F];
		String s = new String(ob);
		return s;
	}
393667
public static void writeBytes(byte b[], int offset, byte[] value) {
    System.arraycopy(value, 0, b, offset, value.length);
  }
1049667
public static void writeSingleByte(OutputStream out, int b) throws IOException {
        byte[] buffer = new byte[1];
        buffer[0] = (byte) (b & 0xff);
        out.write(buffer);
    }
327216
public static String encodeBytes( byte[] source, int off, int len )
    {
        return encodeBytes( source, off, len, true );
    }
995591
public static String strFromUnicodeByteArray(byte[] ba, int len) {
		if (ba == null) {
			return "";
		}

		byte[] newBa = new byte[len];
		for (int i = 0; i < len; i++)
			newBa[i] = ba[i];

		StringBuffer sb = new StringBuffer();
		DataInputStream dis = new DataInputStream(new ByteArrayInputStream(
				newBa));
		while (true) {
			try {
				char c = dis.readChar();
				sb.append(c);
			} catch (Exception e) {
				break;
			}
		}
		return sb.toString();
	}
985370
public void write(byte[] b, int off, int len) throws IOException {
        Boolean result = (Boolean) callback.call(consoleId.get(), new String(b, off, len));
        if (result) {
            out.write(b, off, len);
        }
    }
507791
public static String toHexString(byte[] b) {
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (byte aByte : b) {
            // look up high nibble char
            sb.append(hexChar[(aByte & 0xf0) >>> 4]);

            // look up low nibble char
            sb.append(hexChar[aByte & 0x0f]);
        }
        return sb.toString();
    }
186959
@Override
    public void write(byte[] b, int off, int len) throws IOException
    {
        int wbytes = len;
        int offset = off;
        
        while( wbytes > 0 )
        {
            if ( buf.position() >= buf.capacity() )
            {
                flush();
            }
            
            int length = Math.min( wbytes, buf.limit() - buf.position() );
            
            buf.put(b, offset, length);
            
            offset += length;
            wbytes -= length;
        }
    }
557262
public static String toBinaryString(byte[] b) {
    StringBuilder s = new StringBuilder();
    for (byte by : b) {
      for (int j = 7; j >= 0; j--) {
        if ((by & (1 << j)) > 0) {
          s.append('1');
        } else {
          s.append('0');
        }
      }
      s.append(' ');
    }
    return s.toString();
  }
875663
public static void dump(PrintStream out, byte[] b, int off, int len) {
		int end = off + len;
		int offDiv16 = off / 16;
		int endDiv16 = end / 16;
		if (offDiv16 == endDiv16) {
			out.println(dumpLine(b, offDiv16, off % 16, end % 16));
		} else {
			out.println(dumpLine(b, offDiv16, off % 16, 16));
			for (int i = offDiv16 + 1; i < endDiv16; i ++) {
				out.println(dumpLine(b, i, 0, 16));
			}
			if (end % 16 > 0) {
				out.println(dumpLine(b, endDiv16, 0, end % 16));
			}
		}
	}
627653
public static String toHex(byte []bytes, int offset, int len)
  {
    if (bytes == null)
      return "null";
    
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < len; i++) {
      int d1 = (bytes[offset + i] >> 4) & 0xf;
      int d2 = (bytes[offset + i]) & 0xf;

      if (d1 < 10)
        sb.append((char) ('0' + d1));
      else
        sb.append((char) ('a' + d1 - 10));

      if (d2 < 10)
        sb.append((char) ('0' + d2));
      else
        sb.append((char) ('a' + d2 - 10));
    }

    return sb.toString();
  }
1033406
public static byte[] sub(byte[] b, int off, int len) {
		byte[] result = new byte[len];
		System.arraycopy(b, off, result, 0, len);
		return result;
	}
478348
public static String binToHexString(byte[] bytes, int offset, int len) {
        return new String(binToHex(bytes, offset, len));
    }
1136311
private static String byte2hex(byte[] b) {
		StringBuilder hs = new StringBuilder();
		String stmp;
		for (int n = 0; b!=null && n < b.length; n++) {
			stmp = Integer.toHexString(b[n] & 0XFF);
			if (stmp.length() == 1)
				hs.append('0');
			hs.append(stmp);
		}
		return hs.toString().toUpperCase();
	}
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();
  }
277180
public void write(String str, int off, int len)  {
    	char[] chars = new char[len];
    	str.getChars(off, off+len, chars, 0);
    	buf.append(chars);
    }