Hello all
I used HttpClinet (the get method) to download a zip file from the Tomcat
server. All works fine, expect the zip file downloaded is corrupted. Yes I
can extract the content by using command "unzip", but I got the error of
"file #1: bad zipfile offset (local header sig): 0"
unzip out.zip
Archive: out.zip
file #1: bad zipfile offset (local header sig): 0
replace gs2mgppdemo/etc/collectionConfig.xml? [y]es, [n]o, [A]ll, [N]one,
[r]ename: A
inflating: gs2mgppdemo/etc/collectionConfig.xml
inflating: gs2mgppdemo/metadata/dls.mds
inflating: gs2mgppdemo/metadata/ex.mds
inflating: gs2mgppdemo/metadata/profile.xml
inflating: infomine/etc/collectionConfig.xml
This error caused failure of unziping the file when using the java code. The
error message is below:
java.lang.InternalError: jzentry == 0,
jzfile = 134895168,
total = 17,
name = /research/qq6/out.zip,
i = 1,
message = invalid LOC header (bad signature)
at java.util.zip.ZipFile$2.nextElement(ZipFile.java:323)
at org.greenstone.gatherer.util.UnzipTools.unzipFile(UnzipTools.java
:46)
The size of the zip file downloaded is exactly the same with the original
one though, two files seem different when I run "diff" to compare them.
Does anyone tell me what's going wrong here?
The java code for saving the response stream to a zip file is :
InputStream in = getMethod.getResponseBodyAsStream();
byte[] b = new byte[1024];
int len = in.read(b);
if (len >= 0) {
FileOutputStream zip_fos = new
FileOutputStream("/research/qq6/out.zip");
int offset = 0;
while (len >=0) {
zip_fos.write(b, 0, len);
len = in.read(b, offset, 1024);
}
}
The perl script for reading the zip file into STDOUT is :
$file_path="/research/qq6/qq6-collection-configurations.zip";
if (open(PIN, "<$file_path")) {
print STDOUT "Content-Type:application/zip\n\n";
my $buf;
my $num_bytes = 0;
binmode(PIN);
binmode(STDOUT);
while (read(PIN, $buf, 1024) > 0) {
print STDOUT $buf;
$num_bytes += length($buf);
}
close(PIN);
}
Sorry for my English.