Stumbled across this:
When reading into a byte array using an InputStream you need to check the number of bytes written (may have written less than the length of the array passed). Consequently in the situation above you need a loop (or some helper method) to ensure the full length is written to.