Java Utililty Methods XML Data Type Converter

List of utility methods to do XML Data Type Converter

Description

The list of methods to do XML Data Type Converter are organized into topic(s).

Method

byte[]stringToData(String data)
Convert a string into a binary byte array.
if (data.startsWith("0x")) {
    return DatatypeConverter.parseHexBinary(data.substring(2));
} else {
    try {
        return data.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        return new byte[0];
byte[]toBinaryKeyId(String keyId)
to Binary Key Id
return DatatypeConverter.parseHexBinary(keyId);
StringtoPlaintext(String encryptedText, String password)
to Plaintext
if (encryptedText == null) {
    return null;
if (encryptedText.startsWith(OBFUSCATE)) {
    return deobfuscate(encryptedText);
} else if (encryptedText.startsWith(ENCODE) && password != null) {
    return decrypt(encryptedText, password);
return encryptedText;
StringtoRoboCommand(int command)
to Robo Command
final String hexCommand = toRoboHex(command);
final String packet = PREFIX + DYNAMIXEL_ID + COMMAND_PACKET_LENGTH + INSTRUCTION_WRITE + ADDRESS_EXECUTE
        + hexCommand;
final int cr16 = calculateCR16(packet);
final String cr16RoboHex = toRoboHex(cr16);
return packet + cr16RoboHex;
StringtoString(byte[] edid)
Converts a byte array to a hexadecimal string
return DatatypeConverter.printHexBinary(edid);
StringtoString(final Serializable o)
Write the object to a Base64 string.
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
oos.close();
return new String(DatatypeConverter.printBase64Binary(baos.toByteArray()));
StringtoString(Serializable o)
Converts the specified object into a base64 encoded string.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
    ObjectOutputStream objectStream = new ObjectOutputStream(stream);
    objectStream.writeObject(o);
    objectStream.close();
    return DatatypeConverter.printBase64Binary(stream.toByteArray());
} catch (IOException e) {
    throw new RuntimeException(e.toString(), e);
...
longtoTime(String st)
to Time
return DatatypeConverter.parseDateTime(st).getTimeInMillis();
StringunserializeURLSafe(String string)
Unserialize the given serialized URL-safe string.
if (string == null) {
    return null;
try {
    String base64 = string.replace('~', '/').replace('-', '+').replace('_', '=');
    InputStream deflated = new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(base64));
    ByteArrayOutputStream raw = new ByteArrayOutputStream();
    stream(new InflaterInputStream(deflated), raw);
...
voidwriteKey(Writer writer, PublicKey publicKey)
Write Public Key in PEM format to the writer.
writer.write(PUBLIC_KEY_PREFIX);
writer.write('\n');
String base64 = generateBase64(publicKey);
char[] charArray = base64.toCharArray();
for (int i = 0; i < charArray.length; i += 64) {
    int length = Math.min(charArray.length - i, 64);
    writer.write(charArray, i, length);
    writer.write('\n');
...