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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Author

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

Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 90
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: 90
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
 
Similar Threads
unzip problem, I give up now
xml file display in dowload from servlet
Create ZIP file from servlet
Problem unzipping with ZipInputStream, containing filename with Swedish characters
making a download servlet to service download managers