Example usage for javax.xml.bind DatatypeConverter parseHexBinary

List of usage examples for javax.xml.bind DatatypeConverter parseHexBinary

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseHexBinary.

Prototype

public static byte[] parseHexBinary(String lexicalXSDHexBinary) 

Source Link

Document

Converts the string argument into an array of bytes.

Usage

From source file:Main.java

static public byte[] toByteArray(String hexDumpString) {
    return DatatypeConverter.parseHexBinary(hexDumpString.replaceAll(" ", ""));
}

From source file:Main.java

/**
 *
 * @param content/*from   w  w  w . ja  v a2s  . c o  m*/
 * @param charset
 * @return
 */
public static String parseHexBinary(String content, Charset charset) {

    String converted = content;

    if (content != null && !content.isEmpty()) {
        converted = new String(DatatypeConverter.parseHexBinary(content), charset);
    }

    return converted;
}

From source file:net.pot8os.heartbleedchecker.HexUtil.java

public static byte[] hex2bin(String input) {
    input = input.replace(" ", "");
    return DatatypeConverter.parseHexBinary(input);
}

From source file:keepinchecker.network.PacketParser.java

public static String convertToHumanReadableFormat(Packet packet) {
    String hexString = ByteArrays.toHexString(packet.getRawData(), "");
    byte[] hexBinary = DatatypeConverter.parseHexBinary(hexString);

    return new String(hexBinary);
}

From source file:org.esupportail.papercut.services.HashService.java

public void setHmacKey(String hmacKey) {
    secretKey = new SecretKeySpec(DatatypeConverter.parseHexBinary(hmacKey), "HmacSHA512");
}

From source file:HttpClientJniTest.java

@Test
public void testSimple() throws Exception {
    long handle = 0;
    try {//from   w w w .  j a va 2  s. c om
        String sout = wiltoncall("server_create", GSON.toJson(
                ImmutableMap.builder().put("views", TestGateway.views()).put("tcpPort", TCP_PORT).build()));
        Map<String, Long> shamap = GSON.fromJson(sout, LONG_MAP_TYPE);
        handle = shamap.get("serverHandle");
        String resp = wiltoncall("httpclient_send_request",
                GSON.toJson(ImmutableMap.builder().put("url", ROOT_URL + "hello")
                        .put("metadata", ImmutableMap.builder().put("forceHttp10", true).build()).build()));
        Map<String, Object> map = GSON.fromJson(resp, MAP_TYPE);
        byte[] bytes = DatatypeConverter.parseHexBinary((String) map.get("dataHex"));
        assertEquals(HELLO_RESP, new String(bytes, "UTF-8"));
    } finally {
        wiltoncall("server_stop", GSON.toJson(ImmutableMap.builder().put("serverHandle", handle).build()));
    }
}

From source file:io.cos.cas.adaptors.postgres.models.OpenScienceFrameworkTimeBasedOneTimePassword.java

/**
 * Returns the TOTP secret in encoded as Base32.
 *
 * @return the encoded secret//from  w  ww .jav a2  s.  co m
 */
public String getTotpSecretBase32() {
    final byte[] bytes = DatatypeConverter.parseHexBinary(totpSecret);
    return new Base32().encodeAsString(bytes);
}

From source file:acmi.l2.clientmod.bytecode_editor.calc.CalcController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    BooleanBinding disable = unrealPackageProperty().isNull();
    bytes.disableProperty().bind(disable);
    tokens.disableProperty().bind(disable);

    bytes.textProperty().bindBidirectional(tokens.textProperty(), new StringConverter<String>() {
        @Override/* ww w. j  a v a2s  .  c o m*/
        public String fromString(String string) {
            string = string.replaceAll("\\s", "");

            if (string.length() % 2 == 1)
                return "";

            try {
                BytecodeContext context = new BytecodeContext(getUnrealPackage());
                ObjectInputStream<BytecodeContext> ois = new ObjectInputStream<>(
                        new ByteArrayInputStream(DatatypeConverter.parseHexBinary(string)),
                        getUnrealPackage().getFile().getCharset(), tokenSerializer, context);
                Token token = ois.readObject(Token.class);
                size.setText(String.valueOf(token.getSize(context)));
                return token.toString();
            } catch (UncheckedIOException ignore) {
            } catch (IllegalArgumentException e) {
                return e.getMessage();
            }
            return "";
        }

        @Override
        public String toString(String object) {
            try {
                Token token = (Token) shell.evaluate("def methodMissing(String name, args) {\n"
                        + "Class.forName(\"acmi.l2.clientmod.unreal.bytecode.token.$name\").newInstance(args)\n"
                        + "}\n" + object);

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                BytecodeContext context = new BytecodeContext(getUnrealPackage());
                size.setText(String.valueOf(token.getSize(context)));
                ObjectOutputStream<BytecodeContext> oos = new ObjectOutputStream<>(baos,
                        getUnrealPackage().getFile().getCharset(), tokenSerializer, context);
                oos.write(token);
                return DatatypeConverter.printHexBinary(baos.toByteArray());
            } catch (Exception ignore) {
                return "";
            }
        }
    });
}

From source file:HttpClientJniTest.java

@Test
public void testPost() throws Exception {
    long handle = 0;
    try {//from w w  w  .ja  v  a2 s .com
        String sout = wiltoncall("server_create", GSON.toJson(
                ImmutableMap.builder().put("views", TestGateway.views()).put("tcpPort", TCP_PORT).build()));
        Map<String, Long> shamap = GSON.fromJson(sout, LONG_MAP_TYPE);
        handle = shamap.get("serverHandle");
        String resp = wiltoncall("httpclient_send_request",
                GSON.toJson(ImmutableMap.builder().put("url", ROOT_URL + "postmirror").put("data", "foo")
                        .put("metadata", ImmutableMap.builder().put("forceHttp10", true).build()).build()));
        Map<String, Object> map = GSON.fromJson(resp, MAP_TYPE);
        byte[] bytes = DatatypeConverter.parseHexBinary((String) map.get("dataHex"));
        assertEquals("foo", new String(bytes, "UTF-8"));
    } finally {
        wiltoncall("server_stop", GSON.toJson(ImmutableMap.builder().put("serverHandle", handle).build()));
    }
}

From source file:com.exalttech.trex.util.TrafficProfile.java

/**
 *
 * @param hexPacket/*w  w w  .  java 2s  .co m*/
 * @return Converts a Hex packet to a base64 encoded packet.
 */
public String encodeBinaryFromHexString(String hexPacket) {
    if (!Util.isNullOrEmpty(hexPacket)) {
        byte[] rawData = DatatypeConverter.parseHexBinary(hexPacket);
        return new String(Base64.encodeBase64(rawData));
    }
    return null;
}