I have :
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
encoder.encode(question, outputStream);
and when System.out.println(outputStream) prints this .. i see 0►☻☺♣▬♂test some and I want to see this in HEX like 30 04 12 54 33
How can I do that ?
Thanks
I was able to write the binary to a file like this :
File file = new File("out.bin");
FileOutputStream filename = new FileOutputStream(file);
outputStream.writeTo(filename);
Although the
System.out.println()method can print different things out, it is mainly for printing strings. For this purpose, it will try to convert the input into character string according to the platform or some explicitly given character encoding. To print raw bytes as hex, you need some manipulation before printing them out. The following example might be useful to you.The
getHexmethod is from http://www.rgagnon.com/javadetails/java-0596.html