| Author |
End-of-central-directory signature not found during zip download
|
Adrien Ruffie
Ranch Hand
Joined: Jan 14, 2009
Posts: 71
|
|
Hello everyone I have a problem during a zip file download.
I have a servlet which return the required file:
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException{
// super.doGet(req, resp);
final String params = this.requestExtractor(req);
final File artifactDir = GeneralHelper.getArtifactsRepo();
final File artifactFile = new File(artifactDir, params);
final String[] splittedParams = params.split("/");
if (artifactFile.exists()) {
//resp.setContentType(new MimetypesFileTypeMap().getContentType(artifactFile));
resp.setContentType(req.getSession().getServletContext().getMimeType(artifactFile.getName()));
resp.setHeader("Content-Disposition", "attachment; filename="
+ splittedParams[splittedParams.length - 1]);
resp.setContentLength((int)artifactFile.length());
final OutputStream out = resp.getOutputStream();
final FileInputStream in = new FileInputStream(artifactFile);
try{
final String cacheControl = (String) ConfigHelper
.getConfigurationProperty("cache.control");
resp.setHeader("Cache-Control", cacheControl); // HTTP 1.1
resp.setHeader("Pragma", cacheControl); // HTTP 1.0
final byte buffer[] = new byte[512 * 1024];
int nbLecture;
while ((nbLecture = in.read(buffer)) != -1) {
out.write(buffer, 0, nbLecture);
}
} finally {
in.close();
out.flush();
out.close();
}
} else {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource not found ["
+ splittedParams[splittedParams.length - 1] + "]");
}
}
I download it with "wget" under Ubuntu for example: wget http://localhost:9090/webapp/rest/artifacts/components/component-1.zip
But when I try a "unzip component-1.zip" for this file, its doesn't work :'( and the following message is displayed in Console:
Archive: component-1.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of component-1.zip or
component-1.zip.zip, and cannot find component-1.zip.ZIP, period.
Do you have an idea to resolve this problem ?
Thank
Adrien
|
SCJP 5, SCDJWS 5
http://adrien-ruffie.blogspot.com
|
 |
Adrien Ruffie
Ranch Hand
Joined: Jan 14, 2009
Posts: 71
|
|
|
Problem resolved, it was due to a security constraint affected to this servlet, in the web.xml
|
 |
 |
|
|
subject: End-of-central-directory signature not found during zip download
|
|
|