Example usage for javax.xml.bind DatatypeConverter printHexBinary

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

Introduction

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

Prototype

public static String printHexBinary(byte[] val) 

Source Link

Document

Converts an array of bytes into a string.

Usage

From source file:Main.java

/**
 *
 * @param content//from  ww  w .  j a v  a  2  s.  co m
 * @param charset
 * @return
 */
public static String printHexBinary(String content, Charset charset) {

    String converted = content;

    if (content != null && !content.isEmpty()) {
        converted = DatatypeConverter.printHexBinary(content.getBytes(charset));
    }

    return converted;
}

From source file:com.omnigon.aem.handlebars.helpers.UniqueIdHelper.java

private String generateUniqueId() {
    byte[] bytesDirectoryPath;
    MessageDigest md;//from  w  w w.  j a  v  a 2s  . co  m
    try {
        bytesDirectoryPath = UUID.randomUUID().toString().getBytes(CharEncoding.UTF_8);
        md = MessageDigest.getInstance(MESSAGE_DIGEST_TYPE);
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        LOG.error(e.getMessage(), e);
        return StringUtils.EMPTY;
    }
    md.reset();
    md.update(bytesDirectoryPath);

    String uniqueId = DatatypeConverter.printHexBinary(md.digest());
    String formattedUniqueId = formatUniqueId(uniqueId);

    return formattedUniqueId;
}

From source file:finale.year.stage.utility.Util.java

public static String encryptPassword(String unencrypted) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance(SHA_256);
    md.update(unencrypted.getBytes());//from ww w .j ava 2  s . c om
    return DatatypeConverter.printHexBinary(md.digest()).toLowerCase();
}

From source file:database.HashTablesTools.java

public static String getMD5hash(String pathToFile) throws NoSuchAlgorithmException, IOException {

    byte[] b = Files.readAllBytes(Paths.get(pathToFile));
    byte[] hash = MessageDigest.getInstance("MD5").digest(b);
    String actual = DatatypeConverter.printHexBinary(hash);
    return actual;
}

From source file:net.bluehornreader.model.User.java

@Override
public String toString() {
    return "User{" + "userId='" + userId + '\'' + ", name='" + name + '\'' + ", password="
            + DatatypeConverter.printHexBinary(password) + ", salt='" + salt + '\'' + ", email='" + email + '\''
            + ", feedIds='" + feedIds + '\'' + ", active=" + active + ", admin=" + admin + '}';
}

From source file:com.exalttech.trex.ui.views.streams.viewer.PacketParser.java

/**
 * Extract packet info//from w  w w .j a  v  a2  s  .c  om
 *
 * @param packet
 * @return
 */
private PacketInfo extractPacketInfo(Packet packet) {

    if (packet != null) {
        packetInfo.setPacketHex(formatHex(DatatypeConverter.printHexBinary(packet.getRawData())));
        packetInfo.setPacketRawData(formatPayLoad(new String(packet.getRawData())));
    }

    // defien whether packet has vlan or not
    if (packet.get(Dot1qVlanTagPacket.class) != null) {
        packetInfo.setVlanPacket(true);
    }
    // If the packet has Ethernet
    if (packet.get(EthernetPacket.class) != null) {
        packetInfo.setEthernetHex(
                getHeaderOffset(packet.get(EthernetPacket.class).getHeader().toHexString().toUpperCase()));
        packetInfo.setEthernetRawData(new String());
        packetInfo.setDestMac(packet.get(EthernetPacket.class).getHeader().getDstAddr().toString());
        packetInfo.setSrcMac(packet.get(EthernetPacket.class).getHeader().getSrcAddr().toString());
    }

    // if the packet has IPV4
    if (packet.get(IpV4Packet.class) != null) {
        packetInfo.setIpv4Hex(
                getHeaderOffset(packet.get(IpV4Packet.class).getHeader().toHexString().toUpperCase()));
        packetInfo.setIpv4RawData(new String());
        packetInfo.setDestIpv4(packet.get(IpV4Packet.class).getHeader().getDstAddr().getHostAddress());
        packetInfo.setSrcIpv4(packet.get(IpV4Packet.class).getHeader().getSrcAddr().getHostAddress());
    }

    // if the packet has TCP
    if (packet.get(TcpPacket.class) != null) {
        packetInfo.setL4Name("TCP");
        packetInfo
                .setL4Hex(getHeaderOffset(packet.get(TcpPacket.class).getHeader().toHexString().toUpperCase()));
        packetInfo.setL4RawData(new String());
        if (packet.get(TcpPacket.class).getPayload() != null) {
            packetInfo.setPacketPayLoad(getHeaderOffset(
                    spaceHex(Hex.encodeHexString(packet.get(TcpPacket.class).getPayload().getRawData()))));
        } else {
            packetInfo.setPacketPayLoad(null);
        }
    }

    // if the packet has UDP
    if (packet.get(UdpPacket.class) != null) {
        packetInfo.setL4Name("UDP");
        packetInfo
                .setL4Hex(getHeaderOffset(packet.get(UdpPacket.class).getHeader().toHexString().toUpperCase()));
        packetInfo.setL4RawData(new String());

        if (packet.get(UdpPacket.class).getPayload() != null) {
            packetInfo.setPacketPayLoad(getHeaderOffset(
                    spaceHex(Hex.encodeHexString(packet.get(UdpPacket.class).getPayload().getRawData()))));
        } else {
            packetInfo.setPacketPayLoad(null);
        }
    }
    return packetInfo;
}

From source file:com.actian.ilabs.dataflow.stringtemplate.runner.RunStringTemplate.java

private String FormatFieldValue(ScalarInputField field) {
    ScalarTokenType type = field.getType();
    String valueString = "";

    if (type.equals(TokenTypeConstant.BOOLEAN)) {
        BooleanInputField boolField = (BooleanInputField) field;
        valueString = DatatypeConverter.printBoolean(boolField.asBoolean());
    } else if (type.equals(TokenTypeConstant.BINARY)) {
        BinaryInputField binField = (BinaryInputField) field;
        valueString = DatatypeConverter.printHexBinary(binField.asBinary());
    } else if (type.equals(TokenTypeConstant.CHAR)) {
        CharInputField charField = (CharInputField) field;
        valueString = charField.toString();
    } else if (type.equals(TokenTypeConstant.DATE)) {
        DateInputField dateField = (DateInputField) field;
        DateFormatter dateFormatter = new DateFormatter("yyyyMMdd");
        dateFormatter.setSource(dateField);
        valueString = dateFormatter.format();
    } else if (type.equals(TokenTypeConstant.DOUBLE)) {
        DoubleInputField doubleField = (DoubleInputField) field;
        valueString = DatatypeConverter.printDouble(doubleField.asDouble());
    } else if (type.equals(TokenTypeConstant.FLOAT)) {
        FloatInputField floatField = (FloatInputField) field;
        valueString = DatatypeConverter.printFloat(floatField.asFloat());
    } else if (type.equals(TokenTypeConstant.INT)) {
        IntInputField intField = (IntInputField) field;
        valueString = DatatypeConverter.printInt(intField.asInt());
    } else if (type.equals(TokenTypeConstant.LONG)) {
        LongInputField longField = (LongInputField) field;
        valueString = DatatypeConverter.printLong(longField.asLong());
    } else if (type.equals(TokenTypeConstant.NUMERIC)) {
        NumericInputField numericField = (NumericInputField) field;
        valueString = DatatypeConverter.printDecimal(numericField.asBigDecimal());
    } else if (type.equals(TokenTypeConstant.STRING)) {
        StringInputField stringField = (StringInputField) field;
        valueString = DatatypeConverter.printString(stringField.asString());
    } else if (type.equals(TokenTypeConstant.TIME)) {
        TimeInputField timeField = (TimeInputField) field;
        TimeFormatter timeFormatter = new TimeFormatter("HHmmss.SSSZ");
        timeFormatter.setSource(timeField);
        valueString = timeFormatter.format();
    } else if (type.equals(TokenTypeConstant.TIMESTAMP)) {
        TimestampInputField timestampField = (TimestampInputField) field;
        TimestampFormatter timestampFormatter = new TimestampFormatter("yyyyMMdd'T'HHmmss.SSSZ");
        timestampFormatter.setSource(timestampField);
        valueString = timestampFormatter.format();
    } else {//from   www . jav  a2  s  . c o  m
        valueString = "";
    }

    return valueString;
}

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  a 2s.  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:ws.doerr.cssinliner.email.mandrill.MandrillEmailService.java

public boolean isChanged(String body, Map<String, String> meta, String templateNamePrefix) throws Exception {
    try {//  ww  w  .  j av a 2 s.c om
        String templateName = templateNamePrefix + meta.get(META_TEMPLATE_NAME);
        MessageDigest digest = MessageDigest.getInstance("SHA-256");

        // Get the hash from the current document
        String hash = DatatypeConverter.printHexBinary(digest.digest(body.getBytes("UTF-8")));
        String template = getTemplate(templateName);

        if (template == null) {
            return true;
        } else {
            String templateHash = DatatypeConverter.printHexBinary(digest.digest(template.getBytes("UTF-8")));
            return templateHash.equals(hash);
        }
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Exception communicating with Mandrill", ex);
        throw ex;
    } catch (NoSuchAlgorithmException ex) {
        LOG.log(Level.SEVERE, "Exception getting SHA-256 digest instance", ex);
        throw ex;
    }
}

From source file:com.ibm.cics.ca1y.Util.java

/**
 * Return a string of hexadecimal that represents the byte array. If
 * byteArray is null an empty string is returned.
 * // w  w w.ja  va  2  s .  co m
 * @param byteArray
 *            - byte array to use.
 * @return String of hexadecimal.
 */
public static String getHex(byte[] byteArray) {
    // Return a hex string that represents the byte array byteArray
    if ((byteArray == null) || (byteArray.length == 0)) {
        return "";
    }

    return "0x" + DatatypeConverter.printHexBinary(byteArray);
}