List of usage examples for org.apache.commons.compress.archivers.zip Zip64Mode Always
Zip64Mode Always
To view the source code for org.apache.commons.compress.archivers.zip Zip64Mode Always.
Click Source Link
From source file:cz.cuni.mff.ufal.AllBitstreamZipArchiveReader.java
@Override public void generate() throws IOException, SAXException, ProcessingException { if (redirect != NO_REDIRECTION) { return;/*w w w . ja v a2 s . co m*/ } String name = item.getName() + ".zip"; try { // first write everything to a temp file String tempDir = ConfigurationManager.getProperty("upload.temp.dir"); String fn = tempDir + File.separator + "SWORD." + item.getID() + "." + UUID.randomUUID().toString() + ".zip"; OutputStream outStream = new FileOutputStream(new File(fn)); ZipArchiveOutputStream zip = new ZipArchiveOutputStream(outStream); zip.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zip.setLevel(Deflater.NO_COMPRESSION); ConcurrentMap<String, AtomicInteger> usedFilenames = new ConcurrentHashMap<String, AtomicInteger>(); Bundle[] originals = item.getBundles("ORIGINAL"); if (needsZip64) { zip.setUseZip64(Zip64Mode.Always); } for (Bundle original : originals) { Bitstream[] bss = original.getBitstreams(); for (Bitstream bitstream : bss) { String filename = bitstream.getName(); String uniqueName = createUniqueFilename(filename, usedFilenames); ZipArchiveEntry ze = new ZipArchiveEntry(uniqueName); zip.putArchiveEntry(ze); InputStream is = bitstream.retrieve(); Utils.copy(is, zip); zip.closeArchiveEntry(); is.close(); } } zip.close(); File file = new File(fn); zipFileSize = file.length(); zipInputStream = new TempFileInputStream(file); } catch (AuthorizeException e) { log.error(e.getMessage(), e); throw new ProcessingException("You do not have permissions to access one or more files."); } catch (Exception e) { log.error(e.getMessage(), e); throw new ProcessingException("Could not create ZIP, please download the files one by one. " + "The error has been stored and will be solved by our technical team."); } // Log download statistics for (int bitstreamID : bitstreamIDs) { DSpaceApi.updateFileDownloadStatistics(userID, bitstreamID); } response.setDateHeader("Last-Modified", item.getLastModified().getTime()); // Try and make the download file name formated for each browser. try { String agent = request.getHeader("USER-AGENT"); if (agent != null && agent.contains("MSIE")) { name = URLEncoder.encode(name, "UTF8"); } else if (agent != null && agent.contains("Mozilla")) { name = MimeUtility.encodeText(name, "UTF8", "B"); } } catch (UnsupportedEncodingException see) { name = "item_" + item.getID() + ".zip"; } response.setHeader("Content-Disposition", "attachment;filename=" + name); byte[] buffer = new byte[BUFFER_SIZE]; int length = -1; try { response.setHeader("Content-Length", String.valueOf(this.zipFileSize)); while ((length = this.zipInputStream.read(buffer)) > -1) { out.write(buffer, 0, length); } out.flush(); } finally { try { if (this.zipInputStream != null) { this.zipInputStream.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { // Closing the stream threw an IOException but do we want this to propagate up to Cocoon? // No point since the user has already got the file contents. log.warn("Caught IO exception when closing a stream: " + ioe.getMessage()); } } }
From source file:org.alfresco.repo.exporter.ACPExportPackageHandler.java
public void startExport() { // ALF-2016/*from ww w .ja v a 2 s . com*/ zipStream = new ZipArchiveOutputStream(outputStream); // NOTE: This encoding allows us to workaround bug... // http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807 zipStream.setEncoding("UTF-8"); zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zipStream.setUseLanguageEncodingFlag(true); zipStream.setFallbackToUTF8(true); zipStream.setUseZip64(Zip64Mode.Always); }
From source file:org.callimachusproject.io.CarOutputStream.java
public CarOutputStream(OutputStream out) throws IOException { this.zipStream = new ZipArchiveOutputStream(out); zipStream.setUseZip64(Zip64Mode.Always); }