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

StringdeCrypt(String property)
de Crypt
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(property)), "UTF-8");
ObjectdeserializeFromString(String x)
deserialize From String
try {
    byte[] A = DatatypeConverter.parseBase64Binary(x);
    ByteArrayInputStream bin = new ByteArrayInputStream(A);
    ObjectInputStream in = new ObjectInputStream(bin);
    return in.readObject();
} catch (Exception t) {
    throw new RuntimeException(t);
ObjectdeserializeLogic(String logicString)
deserialize Logic
byte[] data = DatatypeConverter.parseBase64Binary(logicString);
try {
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
    return ois.readObject();
} catch (IOException e) {
    throw new RuntimeException(e);
StringencodeBasicHeader(final String username, final String password)
encode Basic Header
return new String(DatatypeConverter.printBase64Binary(
        (username + ":" + Objects.requireNonNull(password)).getBytes(StandardCharsets.UTF_8)));
StringencodeDoubleArray(double[] noData)
encode Double Array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
byte[] rawBytes;
try {
    oos = new ObjectOutputStream(baos);
    oos.writeInt(noData.length);
    for (int i = 0; i < noData.length; i++) {
        oos.writeDouble(noData[i]);
...
StringencodeJavaOpts(String javaOpts)
Encode the JVM options
1.
String javaOptsBase64 = DatatypeConverter.printBase64Binary(javaOpts.getBytes(Charset.forName("UTF-8")));
return String.format("\"%s\"", javaOptsBase64.replace("=", "&equals;"));
Stringencrypt(String plainText, String password)
encrypt
byte[] salt = new byte[8];
SecureRandom random = new SecureRandom();
random.nextBytes(salt);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password.toCharArray()));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(salt, 20));
return ENCODE + DatatypeConverter.printBase64Binary(salt)
...
StringencryptPassword(String unencrypted)
encrypt Password
MessageDigest md = MessageDigest.getInstance(SHA_256);
md.update(unencrypted.getBytes());
return DatatypeConverter.printHexBinary(md.digest()).toLowerCase();
InputStreamfetchUrl(String url, String username, String password)
fetch Url
notNull(url);
notNull(username);
notNull(password);
URLConnection conn = new URL(url).openConnection();
if (!username.isEmpty()) {
    conn.setRequestProperty("Authorization",
            "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes()));
return conn.getInputStream();
StringformatFriendlyName(final byte[] addressBytes)
format Friendly Name
final String base64 = DatatypeConverter.printBase64Binary(addressBytes);
final String slashToMinus = base64.replace('/', '-');
return slashToMinus;