net.sourceforge.plantuml.code.AsciiEncoderHex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.code;
public class AsciiEncoderHex implements URLEncoder {
public String encode(byte data[]) {
if (data == null) {
return "";
}
final StringBuilder result = new StringBuilder(data.length * 2);
for (byte b : data) {
final String val = Integer.toHexString(b & 0xFF);
if (val.length() == 1) {
result.append("0");
}
result.append(val);
}
return result.toString();
}
public byte[] decode(String s) {
final byte result[] = new byte[s.length() / 2];
for (int i = 0; i < result.length; i++) {
result[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
}
return result;
}
}