Java Byte Array Create toByteArray(String value)

Here you can find the source of toByteArray(String value)

Description

to Byte Array

License

Open Source License

Declaration

public static byte[] toByteArray(String value) 

Method Source Code

//package com.java2s;

public class Main {

    public static byte[] toByteArray(String value) {
        int i, j;
        int len = value.length();

        if (value == null) {
            return null;
        } else if (value == "") {
            return null;
        } else if ((len % 2) != 0) {
            return null;
        }//from   www  . j a v a  2 s.  c  o  m

        try {
            byte[] byteValue = new byte[len / 2];
            j = 0;
            for (i = 0; i < byteValue.length; i++) {
                byteValue[i] = (byte) Integer.parseInt(
                        value.substring(j, j + 2), 16);
                j += 2;
            }

            return byteValue;
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. toByteArray(String str, String separator)
  2. toByteArray(String string)
  3. toByteArray(String string)
  4. toByteArray(String strTransInfo)
  5. toByteArray(String uid)
  6. toByteArray(String[] anArray)
  7. toByteArray1D(int[][] d)
  8. toByteArrayBE(byte b)
  9. toByteArrayForPBE(char[] chars)