hexedit AS3 code

This commit is contained in:
Honfika
2013-11-06 21:39:43 +01:00
parent c00c13e9d7
commit 72a9f59da6
5 changed files with 86 additions and 54 deletions

View File

@@ -604,6 +604,26 @@ public class Helper {
return writer.toString();
}
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;
}
public static <T> T timedCall(Callable<T> c, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
FutureTask<T> task = new FutureTask<>(c);
THREAD_POOL.execute(task);