All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbpm.util.ByteUtil Maven / Gradle / Ivy

package org.jbpm.util;

public class ByteUtil {

  private ByteUtil() {
    // hide default constructor to prevent instantiation
  }

  public static String toString(byte[] bytes) {
    if (bytes == null) return "null";
    if (bytes.length == 0) return "[]";
    StringBuffer buf = new StringBuffer();
    for ( int i=0; i>>4)&0x0F));
      buf.append(toHexChar(b&0x0F));
    }
    return buf.toString();
  }

  public static char toHexChar(int i) {
    if ((0 <= i) && (i <= 9))
      return (char) ('0' + i);
    else
      return (char) ('a' + (i - 10));
  }
  
  public static byte[] fromString(String hexString) {
    if (hexString==null) return null;
    if (hexString.length() % 2 != 0)
        throw new IllegalArgumentException("invalid hex string: odd number of hex digits");
    int byteArraySize = hexString.length()/2;
    byte[] bytes = new byte[byteArraySize];
    for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy