Here you can find the source of toHexString(final byte[] data)
Parameter | Description |
---|---|
data | the byte array to be converted to hex string (which cannot be null ) |
Parameter | Description |
---|---|
NullPointerException | if the given byte array is null |
public static String toHexString(final byte[] data) throws NullPointerException
//package com.java2s; /*/* w w w .j a va2 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% */ import java.util.Formatter; public class Main { /** * Converts the given byte array to hex string * * @param data * the byte array to be converted to hex string (which cannot be {@code null}) * @return the converted hex string * @throws NullPointerException * if the given byte array is {@code null} */ public static String toHexString(final byte[] data) throws NullPointerException { try (Formatter formatter = new Formatter()) { for (final byte b : data) { formatter.format("%02x", b); } return formatter.toString(); } } }