List of usage examples for java.util.zip ZipEntry setTime
public void setTime(long time)
From source file:it.greenvulcano.util.zip.ZipHelper.java
private void internalZipFile(File srcFile, ZipOutputStream zos, URI base) throws IOException { String zipEntryName = base.relativize(srcFile.toURI()).getPath(); if (srcFile.isDirectory()) { zipEntryName = zipEntryName.endsWith("/") ? zipEntryName : zipEntryName + "/"; ZipEntry anEntry = new ZipEntry(zipEntryName); anEntry.setTime(srcFile.lastModified()); zos.putNextEntry(anEntry);//from w w w.j a va 2s .co m File[] dirList = srcFile.listFiles(); for (File file : dirList) { internalZipFile(file, zos, base); } } else { ZipEntry anEntry = new ZipEntry(zipEntryName); anEntry.setTime(srcFile.lastModified()); zos.putNextEntry(anEntry); FileInputStream fis = null; try { fis = new FileInputStream(srcFile); IOUtils.copy(fis, zos); zos.closeEntry(); } finally { try { if (fis != null) { fis.close(); } } catch (IOException exc) { // Do nothing } } } }
From source file:ZipImploder.java
/** * process a single file for a .zip file * // w ww.j a v a2 s .com * @param zos * @param f * @throws IOException */ public void processFile(ZipOutputStream zos, File f) throws IOException { String path = f.getCanonicalPath(); path = path.replace('\\', '/'); String xpath = removeDrive(removeLead(path)); ZipEntry ze = new ZipEntry(xpath); ze.setTime(f.lastModified()); ze.setSize(f.length()); zos.putNextEntry(ze); fileCount++; try { copyFileEntry(zos, f); } finally { zos.closeEntry(); } }
From source file:freenet.client.async.ContainerInserter.java
private String createZipBucket(OutputStream os) throws IOException { if (logMINOR) Logger.minor(this, "Create a ZIP Bucket"); ZipOutputStream zos = new ZipOutputStream(os); try {/*w w w . j a va2 s.co m*/ ZipEntry ze; for (ContainerElement ph : containerItems) { ze = new ZipEntry(ph.targetInArchive); ze.setTime(0); zos.putNextEntry(ze); BucketTools.copyTo(ph.data, zos, ph.data.size()); zos.closeEntry(); } } finally { zos.close(); } return ARCHIVE_TYPE.ZIP.mimeTypes[0]; }
From source file:org.lockss.exporter.ZipExporter.java
protected void writeCu(CachedUrl cu) throws IOException { ensureOpenZip();//from www.j av a 2 s . co m CIProperties props = cu.getProperties(); ZipEntry ent = new ZipEntry(xlateFilename(cu.getUrl())); // Store HTTP response headers into entry comment ent.setComment(getHttpResponseString(cu)); String lastMod = props.getProperty(CachedUrl.PROPERTY_LAST_MODIFIED); if (!StringUtil.isNullString(lastMod)) { try { long cuLastModified = dateAsLong(lastMod); ent.setTime(cuLastModified); } catch (RuntimeException e) { } } InputStream ins = cu.getUnfilteredInputStream(); try { zip.putNextEntry(ent); StreamUtil.copy(ins, zip); zip.closeEntry(); // zip.flush(); } finally { IOUtil.safeClose(ins); } }
From source file:org.apache.sling.oakui.OakUIWebConsole.java
private void downloadSegment(@Nonnull HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull String index, @Nonnull String file) throws IOException { NodeStore ns = getNodeStore();//from www. j a va 2s . co m NodeState oakIndex = ns.getRoot().getChildNode("oak:index"); NodeStoreDirectory nsDirectory = new NodeStoreDirectory(oakIndex, index); response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=\"" + index + ".zip\";"); ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream()); for (String f : nsDirectory.listAll()) { ZipEntry ze = new ZipEntry(f); ze.setSize(nsDirectory.fileLength(f)); ze.setTime(nsDirectory.getLastModified(f)); zipOutputStream.putNextEntry(ze); OakIndexInput input = nsDirectory.openInput(f); transferBytes(input, zipOutputStream); zipOutputStream.closeEntry(); } zipOutputStream.finish(); }
From source file:org.openremote.beehive.configuration.www.UsersAPI.java
private void writeZipEntry(ZipOutputStream zipOutput, File file, java.nio.file.Path basePath) throws IOException { ZipEntry entry = new ZipEntry(basePath.relativize(file.toPath()).toString()); entry.setSize(file.length());//from w w w. j av a2 s.co m entry.setTime(file.lastModified()); zipOutput.putNextEntry(entry); IOUtils.copy(new FileInputStream(file), zipOutput); zipOutput.flush(); zipOutput.closeEntry(); }
From source file:org.nuxeo.runtime.deployment.preprocessor.PackWar.java
protected void zipFile(String entryName, File file, ZipOutputStream zout, FileProcessor processor) throws IOException { ZipEntry zentry = new ZipEntry(entryName); if (processor == null) { processor = CopyProcessor.INSTANCE; zentry.setTime(file.lastModified()); }/*from w w w . j a va 2s . c o m*/ zout.putNextEntry(zentry); processor.process(file, zout); zout.closeEntry(); }
From source file:org.codice.ddf.configuration.migration.ImportMigrationEntryImplTest.java
@Test public void constructorWithZipEntry() throws Exception { givenMockedPathUtils();//w w w .j av a 2s . co m final java.util.zip.ZipEntry zipEntry = new java.util.zip.ZipEntry("migratable/" + ENTRY_NAME); zipEntry.setTime(MODIFIED_TIME); final ImportMigrationEntryImpl entry = new ImportMigrationEntryImpl(getContextFunction, zipEntry); assertThat(entry.getContext(), sameInstance(mockContext)); verifyNameAndPathInformation(entry, mockContext); assertThat(entry.isFile(), equalTo(true)); assertThat(entry.isDirectory(), equalTo(false)); assertThat(entry.getLastModifiedTime(), equalTo(MODIFIED_TIME)); }
From source file:edu.umd.cs.submitServer.servlets.UploadSubmission.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { long now = System.currentTimeMillis(); Timestamp submissionTimestamp = new Timestamp(now); // these are set by filters or previous servlets Project project = (Project) request.getAttribute(PROJECT); StudentRegistration studentRegistration = (StudentRegistration) request.getAttribute(STUDENT_REGISTRATION); MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); boolean webBasedUpload = ((Boolean) request.getAttribute("webBasedUpload")).booleanValue(); String clientTool = multipartRequest.getCheckedParameter("submitClientTool"); String clientVersion = multipartRequest.getOptionalCheckedParameter("submitClientVersion"); String cvsTimestamp = multipartRequest.getOptionalCheckedParameter("cvstagTimestamp"); Collection<FileItem> files = multipartRequest.getFileItems(); Kind kind;//from w w w . java 2 s . c om byte[] zipOutput = null; // zipped version of bytesForUpload boolean fixedZip = false; try { if (files.size() > 1) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bos); for (FileItem item : files) { String name = item.getName(); if (name == null || name.length() == 0) continue; byte[] bytes = item.get(); ZipEntry zentry = new ZipEntry(name); zentry.setSize(bytes.length); zentry.setTime(now); zos.putNextEntry(zentry); zos.write(bytes); zos.closeEntry(); } zos.flush(); zos.close(); zipOutput = bos.toByteArray(); kind = Kind.MULTIFILE_UPLOAD; } else { FileItem fileItem = multipartRequest.getFileItem(); if (fileItem == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "There was a problem processing your submission. " + "No files were found in your submission"); return; } // get size in bytes long sizeInBytes = fileItem.getSize(); if (sizeInBytes == 0 || sizeInBytes > Integer.MAX_VALUE) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Trying upload file of size " + sizeInBytes); return; } // copy the fileItem into a byte array byte[] bytesForUpload = fileItem.get(); String fileName = fileItem.getName(); boolean isSpecialSingleFile = OfficeFileName.matcher(fileName).matches(); FormatDescription desc = FormatIdentification.identify(bytesForUpload); if (!isSpecialSingleFile && desc != null && desc.getMimeType().equals("application/zip")) { fixedZip = FixZip.hasProblem(bytesForUpload); kind = Kind.ZIP_UPLOAD; if (fixedZip) { bytesForUpload = FixZip.fixProblem(bytesForUpload, studentRegistration.getStudentRegistrationPK()); kind = Kind.FIXED_ZIP_UPLOAD; } zipOutput = bytesForUpload; } else { // ========================================================================================== // [NAT] [Buffer to ZIP Part] // Check the type of the upload and convert to zip format if // possible // NOTE: I use both MagicMatch and FormatDescription (above) // because MagicMatch was having // some trouble identifying all zips String mime = URLConnection.getFileNameMap().getContentTypeFor(fileName); if (!isSpecialSingleFile && mime == null) try { MagicMatch match = Magic.getMagicMatch(bytesForUpload, true); if (match != null) mime = match.getMimeType(); } catch (Exception e) { // leave mime as null } if (!isSpecialSingleFile && "application/zip".equalsIgnoreCase(mime)) { zipOutput = bytesForUpload; kind = Kind.ZIP_UPLOAD2; } else { InputStream ins = new ByteArrayInputStream(bytesForUpload); if ("application/x-gzip".equalsIgnoreCase(mime)) { ins = new GZIPInputStream(ins); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bos); if (!isSpecialSingleFile && ("application/x-gzip".equalsIgnoreCase(mime) || "application/x-tar".equalsIgnoreCase(mime))) { kind = Kind.TAR_UPLOAD; TarInputStream tins = new TarInputStream(ins); TarEntry tarEntry = null; while ((tarEntry = tins.getNextEntry()) != null) { zos.putNextEntry(new ZipEntry(tarEntry.getName())); tins.copyEntryContents(zos); zos.closeEntry(); } tins.close(); } else { // Non-archive file type if (isSpecialSingleFile) kind = Kind.SPECIAL_ZIP_FILE; else kind = Kind.SINGLE_FILE; // Write bytes to a zip file ZipEntry zentry = new ZipEntry(fileName); zos.putNextEntry(zentry); zos.write(bytesForUpload); zos.closeEntry(); } zos.flush(); zos.close(); zipOutput = bos.toByteArray(); } // [END Buffer to ZIP Part] // ========================================================================================== } } } catch (NullPointerException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "There was a problem processing your submission. " + "You should submit files that are either zipped or jarred"); return; } finally { for (FileItem fItem : files) fItem.delete(); } if (webBasedUpload) { clientTool = "web"; clientVersion = kind.toString(); } Submission submission = uploadSubmission(project, studentRegistration, zipOutput, request, submissionTimestamp, clientTool, clientVersion, cvsTimestamp, getDatabaseProps(), getSubmitServerServletLog()); request.setAttribute("submission", submission); if (!webBasedUpload) { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("Successful submission #" + submission.getSubmissionNumber() + " received for project " + project.getProjectNumber()); out.flush(); out.close(); return; } boolean instructorUpload = ((Boolean) request.getAttribute("instructorViewOfStudent")).booleanValue(); // boolean // isCanonicalSubmission="true".equals(request.getParameter("isCanonicalSubmission")); // set the successful submission as a request attribute String redirectUrl; if (fixedZip) { redirectUrl = request.getContextPath() + "/view/fixedSubmissionUpload.jsp?submissionPK=" + submission.getSubmissionPK(); } if (project.getCanonicalStudentRegistrationPK() == studentRegistration.getStudentRegistrationPK()) { redirectUrl = request.getContextPath() + "/view/instructor/projectUtilities.jsp?projectPK=" + project.getProjectPK(); } else if (instructorUpload) { redirectUrl = request.getContextPath() + "/view/instructor/project.jsp?projectPK=" + project.getProjectPK(); } else { redirectUrl = request.getContextPath() + "/view/project.jsp?projectPK=" + project.getProjectPK(); } response.sendRedirect(redirectUrl); }
From source file:org.dspace.pack.bagit.Bag.java
private void fillZip(File dirFile, String relBase, ZipOutputStream zout) throws IOException { for (File file : dirFile.listFiles()) { String relPath = relBase + File.separator + file.getName(); if (file.isDirectory()) { fillZip(file, relPath, zout); } else {//from w w w. ja v a 2s . com ZipEntry entry = new ZipEntry(relPath); entry.setTime(0L); zout.putNextEntry(entry); FileInputStream fin = new FileInputStream(file); Utils.copy(fin, zout); zout.closeEntry(); fin.close(); } } }