Here you can find the source of toByteArray(final String hexString)
Parameter | Description |
---|---|
hexString | the hex string to be converted to bytes (which cannot be null ) |
Parameter | Description |
---|---|
NullPointerException | if the given hex string is null |
public static byte[] toByteArray(final String hexString) throws NullPointerException
//package com.java2s; /*/*from www.ja v a 2 s . c o m*/ * #%L * JavaCreed Secure Properties Encoder * %% * Copyright (C) 2012 - 2015 Java Creed * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ public class Main { /** * Converts the given hex string to byte array * * @param hexString * the hex string to be converted to bytes (which cannot be {@code null}) * @return the byte array * @throws NullPointerException * if the given hex string is {@code null} */ public static byte[] toByteArray(final String hexString) throws NullPointerException { final int length = hexString.length(); final byte[] bytes = new byte[length / 2]; for (int i = 0; i < length; i += 2) { bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); } return bytes; } }