I have to read JPEG pictures from a database. They are stored as Hex Strings.
For tests I have saved the original hex String to a file, opened it with Notepad++ and applied Convert -> HEX --> ASCII
and saved the result. This is a valid JPEG and can be rendered in a browser.
I have tried to reproduce this in java.
private String hexToASCII(String hex) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < hex.length(); i+=2) {
String str = hex.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
return output.toString();
}
When I save the result to disk, the resulting file is no jpg it begins with
ÿØÿà JFIF ÿÛ C
If have also tried to convert the original hex string with https://www.rapidtables.com/convert/number/hex-to-ascii.html this gives the same result as my code. The resulting file is no jpg. What is Notepad++ doing and how can I reproduce this in Java? Any advise would be greatly appreciated.