I'm working on an iOS and Android app where I have to download PDF files from the server in the form of binary data and write them to the disk. When I try to open the files with Adobe Reader on Android devices I get an invalid format error whilst it is working on iOS.
The relevant code on Android is below:
JSONArray bytesArray = new JSONArray(responseStrBuilder.toString());
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(file)));
for (int i = 0; i < bytesArray.length(); i++) {
dos.writeInt(bytesArray.getInt(i));
}
dos.close();
When I converted the files to .txt files on my mac and opened them up in a text editor, the content seems to be exactly the same except for the fact the one downloaded by the Android app has a lot of blank lines. I'm wondering if this could be the problem and how to overcome it?
I should also point out that I checked the length of the arrays on both platforms, the value of each item being written to the file, etc and it is exactly the same.
I've attached two screenshots, the first of the file downloaded on Android, and the second from iOS.
Any help would be greatly appreciated. Thank you :)
Android Screenshot https://dl.dropboxusercontent.com/u/67408017/Screen%20Shot%202014-02-20%20at%2011.18.41%20AM.png
iOS Screenshot https://dl.dropboxusercontent.com/u/67408017/Screen%20Shot%202014-02-20%20at%2011.18.49%20AM.png