Here you can find the source of getBytesFromHexaText(String text)
public static byte[] getBytesFromHexaText(String text)
//package com.java2s; /*//from w w w .j av a 2 s . c o m * Copyright (C) 2010-2015 JPEXS, All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. */ import java.io.ByteArrayOutputStream; import java.util.Scanner; public class Main { public static byte[] getBytesFromHexaText(String text) { Scanner scanner = new Scanner(text); scanner.nextLine(); // ignore first line ByteArrayOutputStream baos = new ByteArrayOutputStream(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.startsWith(";")) { continue; } line = line.replace(" ", ""); for (int i = 0; i < line.length() / 2; i++) { String hexStr = line.substring(i * 2, (i + 1) * 2); byte b = (byte) Integer.parseInt(hexStr, 16); baos.write(b); } } byte[] data = baos.toByteArray(); return data; } }