0

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

Jerry
  • 13
  • 1
  • 4
  • Make up your mind. Is it JSON data or binary data? – user207421 Feb 19 '14 at 23:12
  • It's binary data ... in a JSON array. I know it does not make sense but we don't control the server and the client will not change it. This is just a small sample .... [37,80,68,70,45,49,46,51,13,37,226,227,207,211,13,10,50,32,48,32,111,98,106, ......] – Jerry Feb 19 '14 at 23:52

0 Answers0