Google App Engine でホストされているサーバーで、別のサーバーからファイルをダウンロードし、(util.zip を使用して) 圧縮し、後でダウンロードするために zip ファイルをアップロードしようとしています。
フォルダーにファイルがあります (html および png ファイル)。ダウンロードと zip とアップロードが成功しました。目的のzipをダウンロードできますが、元のファイルは開けますが、pngファイルを開くことはできません。プログラムがファイル形式をサポートしていないと表示されます。興味深いことに、zip 内の html ファイルに問題はありません。ここで何が問題になるか知っている人はいますか?
前もって感謝します。
- コード -
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());
}