 <p>This does not explain why your method stops so soon, but you need to take care of it or you will have an even stranger problem with the result data being completely garbled.</p> <p>From the APi doc of DataInputStream.read():</p> <blockquote> <p>Reads some number of bytes from the contained input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. </p> </blockquote> <p>You need to use that return value and call the write() method that takes and offset and length.</p>