I needed to initialize a file as part of a unit test. The file conatined binary data. My first thought was UUEncoding, which quickly got upgraded to Base64 encoding. To get it into a format that would then work in Java or C code I used the following line of BASH.
base64 < rui.pfx | sed -e ‘s!\\!\\\\!g’ -e ‘s!\”!\\\”!g’ -e ‘s!$!\\n\”!’ -e ‘s!^!+\”!’
It was for testing a decrypter from using a key generated by SSL.
It is important to double the slashes already existing in the file before you add your own.
Note, I added this as a way to remeber how to put binary Data into code, not as a recommendation for how to mock up for unit test. The correct solution was to use:
InputStream inputStream = this.getClass().getResourceAsStream(
file.getName());