wood burning stoves
The moose likes Servlets and the fly likes End-of-central-directory signature not found during zip download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "End-of-central-directory signature not found during zip download" Watch "End-of-central-directory signature not found during zip download" New topic

End-of-central-directory signature not found during zip download

Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 92
Hello everyone I have a problem during a zip file download.

I have a servlet which return the required file:

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.setHeader("Content-Disposition", "attachment; filename="
+ splittedParams[splittedParams.length - 1]);

final OutputStream out = resp.getOutputStream();
final FileInputStream in = new FileInputStream(artifactFile);

final String cacheControl = (String) ConfigHelper
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 {

} 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 ?



Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 92
Problem resolved, it was due to a security constraint affected to this servlet, in the web.xml
I agree. Here's the link: http://aspose.com/file-tools
subject: End-of-central-directory signature not found during zip download
jQuery in Action, 3rd edition