Android Open Source - anokicert Utils






From Project

Back to project page anokicert.

License

The source code is released under:

GNU General Public License

If you think the Android project anokicert listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.mariotaku.anokicert.util;
/*w ww .j  a  v a  2  s .  c  o  m*/
public final class Utils {
  /** Hexadecimal digits. */
  private static final char[] hc = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

  /**
   * Converts a byte array into a corresponding string of hexadecimal digits.
   * This is equivalent to hexEncode(b, 0, b.length).
   * <P />
   * 
   * @param b byte array to be converted
   * @return corresponding hexadecimal string
   */
  public static String hexEncode(final byte[] b) {
    if (b == null)
      return "";
    else
      return hexEncode(b, 0, b.length);
  }

  /**
   * Converts a subsequence of bytes in a byte array into a corresponding
   * string of hexadecimal digits, each separated by a ":".
   * 
   * @param b byte array containing the bytes to be converted
   * @param off starting offset of the byte subsequence inside b
   * @param len number of bytes to be converted
   * @return a string of corresponding hexadecimal digits or an error string
   */
  public static String hexEncode(final byte[] b, final int off, final int len) {
    return new String(hexEncodeToChars(b, off, len));
  }

  /**
   * Converts a subsequence of bytes in a byte array into a corresponding
   * string of hexadecimal digits, each separated by a ":".
   * 
   * @param b byte array containing the bytes to be converted
   * @param off starting offset of the byte subsequence inside b
   * @param len number of bytes to be converted
   * @return a string of corresponding hexadecimal digits or an error string
   */
  public static char[] hexEncodeToChars(final byte[] b, final int off, final int len) {
    char[] r;
    int v;
    int i;
    int j;

    if (b == null || len == 0) return new char[0];

    if (off < 0 || len < 0) throw new ArrayIndexOutOfBoundsException();

    if (len == 1) {
      r = new char[len * 2];
    } else {
      r = new char[len * 3 - 1];
    }

    for (i = 0, j = 0;;) {
      v = b[off + i] & 0xff;
      r[j++] = hc[v >>> 4];
      r[j++] = hc[v & 0x0f];

      i++;
      if (i >= len) {
        break;
      }

      r[j++] = ':';
    }

    return r;
  }
}




Java Source Code List

net.tuxed.gjokii.DirectoryEntryInfo.java
net.tuxed.gjokii.GjokiiException.java
net.tuxed.gjokii.Gjokii.java
net.tuxed.misc.Utils.java
net.tuxed.nokicert.CertListParser.java
net.tuxed.nokicert.CertParser.java
net.tuxed.nokicert.NokiCertUtils.java
net.tuxed.nokicert.NokiCert.java
org.mariotaku.anokicert.Constants.java
org.mariotaku.anokicert.activity.DeviceCertListActivity.java
org.mariotaku.anokicert.activity.DeviceSelectorActivity.java
org.mariotaku.anokicert.activity.FilePickerActivity.java
org.mariotaku.anokicert.activity.MainActivity.java
org.mariotaku.anokicert.adapter.ArrayAdapter.java
org.mariotaku.anokicert.adapter.BluetoothDevicesListAdapter.java
org.mariotaku.anokicert.adapter.DeviceCertListAdapter.java
org.mariotaku.anokicert.fragment.AlertDialogFragment.java
org.mariotaku.anokicert.fragment.BluetoothUnsupportedDialogFragment.java
org.mariotaku.anokicert.fragment.StackTraceDialogFragment.java
org.mariotaku.anokicert.util.ArrayUtils.java
org.mariotaku.anokicert.util.AsyncNokiCertWrapper.java
org.mariotaku.anokicert.util.Utils.java
org.mariotaku.anokicert.view.MainLinearLayout.java