On a server hosted on google app engine, I am trying to download files from another server, zip (using util.zip) them and upload the zip file for later download.
I have files in a folder (html and png files). The download and zip and upload is successful. I can download the desired zip, however I can not open the png files, even though I can the original ones. It says the program doesn’t support the file format. Interestingly the there are no problems with the html files in the zip.
Does anybody know what can be the problem here?
Thank you in advance.
–THE CODE–
public boolean generateZip(){
byte[] application = new byte[1500000];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(baos);
//This will get the desired file names and locations from the other server
ArrayList<String> others = getFileNames(this);
for(String s: others){
URL url = new URL("http://otherserver.com/" + s);
BufferedReader reader = null;
try{
//I need only the file names not the full directory name
int toSub = s.lastIndexOf("/");
String entryString = s.substring(toSub+1);
out.putNextEntry(new ZipEntry(entryString));
reader = new BufferedReader(new InputStreamReader(url.openStream()));
byte[] buffer = new byte[3000000];
int bindex = 0;
int b = reader.read();
while(b != -1){
buffer[bindex] = (byte) b;
bindex++;
b = reader.read();
}
out.write(buffer,0,bindex);
out.closeEntry();
reader.close();
System.out.println(entryString + " packaged...");
}catch(Exception e){
e.printStackTrace();
}
}
}
out.close();
} catch (IOException e) {
System.out.println("There was an error generating ZIP.");
e.printStackTrace();
}
return uploadZip(baos.toByteArray());
}
Finally I found the solution. For anyone who’s interested: