List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry setUnixMode
public void setUnixMode(int mode)
From source file:org.apache.karaf.tooling.ArchiveMojo.java
private void addFileToZip(ZipArchiveOutputStream tOut, Path f, String base) throws IOException { if (Files.isDirectory(f)) { String entryName = base + f.getFileName().toString() + "/"; ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); tOut.putArchiveEntry(zipEntry);// w w w .ja v a 2 s . co m tOut.closeArchiveEntry(); try (DirectoryStream<Path> children = Files.newDirectoryStream(f)) { for (Path child : children) { addFileToZip(tOut, child, entryName); } } } else if (useSymLinks && Files.isSymbolicLink(f)) { String entryName = base + f.getFileName().toString(); ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); zipEntry.setUnixMode(UnixStat.LINK_FLAG | UnixStat.DEFAULT_FILE_PERM); tOut.putArchiveEntry(zipEntry); tOut.write(Files.readSymbolicLink(f).toString().getBytes()); tOut.closeArchiveEntry(); } else { String entryName = base + f.getFileName().toString(); ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); zipEntry.setSize(Files.size(f)); if (entryName.contains("/bin/") || (!usePathPrefix && entryName.startsWith("bin"))) { if (!entryName.endsWith(".bat")) { zipEntry.setUnixMode(0755); } else { zipEntry.setUnixMode(0644); } } tOut.putArchiveEntry(zipEntry); Files.copy(f, tOut); tOut.closeArchiveEntry(); } }
From source file:org.apache.openejb.maven.plugin.BuildTomEEMojo.java
private void zip(final ZipArchiveOutputStream zip, final File f, final String prefix) throws IOException { final String path = f.getPath().replace(prefix, "").replace(File.separator, "/"); final ZipArchiveEntry archiveEntry = new ZipArchiveEntry(f, path); if (isSh(path)) { archiveEntry.setUnixMode(0755); }/*from ww w . j a va2 s . com*/ zip.putArchiveEntry(archiveEntry); if (f.isDirectory()) { zip.closeArchiveEntry(); final File[] files = f.listFiles(); if (files != null) { for (final File child : files) { zip(zip, child, prefix); } } } else { IO.copy(f, zip); zip.closeArchiveEntry(); } }
From source file:org.apache.sis.internal.maven.Assembler.java
/** * Adds the given file in the ZIP file. If the given file is a directory, then this method * recursively adds all files contained in this directory. This method is invoked for zipping * the "application/sis-console/src/main/artifact" directory and sub-directories before to zip * the Pack200 file.// w w w . ja va2 s. c o m */ private void appendRecursively(final File file, String relativeFile, final ZipArchiveOutputStream out, final byte[] buffer) throws IOException { if (file.isDirectory()) { relativeFile += '/'; } final ZipArchiveEntry entry = new ZipArchiveEntry(file, relativeFile); if (file.canExecute()) { entry.setUnixMode(0744); } out.putArchiveEntry(entry); if (!entry.isDirectory()) { final FileInputStream in = new FileInputStream(file); try { int n; while ((n = in.read(buffer)) >= 0) { out.write(buffer, 0, n); } } finally { in.close(); } } out.closeArchiveEntry(); if (entry.isDirectory()) { for (final String filename : file.list(this)) { appendRecursively(new File(file, filename), relativeFile.concat(filename), out, buffer); } } }
From source file:org.cloudfoundry.util.FileUtils.java
private static void write(Path root, Path path, ZipArchiveOutputStream out) { try {/*from www. ja va 2s .c o m*/ if (Files.isSameFile(root, path)) { return; } ZipArchiveEntry entry = new ZipArchiveEntry(getRelativePathName(root, path)); entry.setUnixMode(getUnixMode(path)); entry.setLastModifiedTime(Files.getLastModifiedTime(path)); out.putArchiveEntry(entry); if (Files.isRegularFile(path)) { Files.copy(path, out); } out.closeArchiveEntry(); } catch (IOException e) { throw Exceptions.propagate(e); } }
From source file:org.codehaus.mojo.unix.maven.zip.ZipUnixPackage.java
private BasicPackageFileSystemObject<F2<UnixFsObject, ZipArchiveOutputStream, IoEffect>> directory( Directory directory) {// w ww . jav a2 s .c o m F2<UnixFsObject, ZipArchiveOutputStream, IoEffect> f = new F2<UnixFsObject, ZipArchiveOutputStream, IoEffect>() { public IoEffect f(final UnixFsObject file, final ZipArchiveOutputStream zos) { return new IoEffect() { public void run() throws IOException { String path = file.path.isBase() ? "." : file.path.asAbsolutePath("./") + "/"; ZipArchiveEntry entry = new ZipArchiveEntry(path); entry.setSize(file.size); entry.setTime(file.lastModified.toDateTime().getMillis()); if (file.attributes.mode.isSome()) { entry.setUnixMode(file.attributes.mode.some().toInt()); } zos.putArchiveEntry(entry); zos.closeArchiveEntry(); } }; } }; return basicPackageFSO(directory, f); }
From source file:org.codehaus.mojo.unix.maven.zip.ZipUnixPackage.java
private BasicPackageFileSystemObject<F2<UnixFsObject, ZipArchiveOutputStream, IoEffect>> file( final Fs<?> fromFile, UnixFsObject file) { F2<UnixFsObject, ZipArchiveOutputStream, IoEffect> f = new F2<UnixFsObject, ZipArchiveOutputStream, IoEffect>() { public IoEffect f(final UnixFsObject file, final ZipArchiveOutputStream zos) { return new IoEffect() { public void run() throws IOException { InputStream inputStream = null; BufferedReader reader = null; try { P2<InputStream, Option<Long>> p = filtersAndLineEndingHandingInputStream(file, fromFile.inputStream()); inputStream = p._1(); long size = p._2().orSome(file.size); ZipArchiveEntry entry = new ZipArchiveEntry(file.path.asAbsolutePath("./")); entry.setSize(size); entry.setTime(file.lastModified.toDateTime().getMillis()); if (file.attributes.mode.isSome()) { entry.setUnixMode(file.attributes.mode.some().toInt()); }//from w ww.j a va2 s. c om zos.putArchiveEntry(entry); copy(inputStream, zos, 1024 * 128); zos.closeArchiveEntry(); } finally { IOUtil.close(inputStream); IOUtil.close(reader); } } }; } }; return basicPackageFSO(file, f); }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
/** * Adds a new entry to the archive, takes care of duplicates as well. * @param in the stream to read data for the entry from. * @param zOut the stream to write to. * @param vPath the name this entry shall have in the archive. * @param lastModified last modification time for the entry. * @param fromArchive the original archive we are copying this * @param symlinkDestination//w ww . j a v a 2 s . c o m */ @SuppressWarnings({ "JavaDoc" }) protected void zipFile(InputStreamSupplier in, ConcurrentJarCreator zOut, String vPath, long lastModified, File fromArchive, int mode, String symlinkDestination) throws IOException, ArchiverException { getLogger().debug("adding entry " + vPath); entries.put(vPath, vPath); if (!skipWriting) { ZipArchiveEntry ze = new ZipArchiveEntry(vPath); setTime(ze, lastModified); ze.setMethod(doCompress ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED); ze.setUnixMode(UnixStat.FILE_FLAG | mode); InputStream payload; if (ze.isUnixSymlink()) { ZipEncoding enc = ZipEncodingHelper.getZipEncoding(getEncoding()); final byte[] bytes = enc.encode(symlinkDestination).array(); payload = new ByteArrayInputStream(bytes); zOut.addArchiveEntry(ze, createInputStreamSupplier(payload)); } else { zOut.addArchiveEntry(ze, wrappedRecompressor(ze, in)); } } }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
protected void zipDir(PlexusIoResource dir, ConcurrentJarCreator zOut, String vPath, int mode, String encodingToUse) throws IOException { if (addedDirs.update(vPath)) { return;// ww w . j ava 2 s . c o m } getLogger().debug("adding directory " + vPath); if (!skipWriting) { final boolean isSymlink = dir instanceof SymlinkDestinationSupplier; if (isSymlink && vPath.endsWith(File.separator)) { vPath = vPath.substring(0, vPath.length() - 1); } ZipArchiveEntry ze = new ZipArchiveEntry(vPath); /* * ZipOutputStream.putNextEntry expects the ZipEntry to * know its size and the CRC sum before you start writing * the data when using STORED mode - unless it is seekable. * * This forces us to process the data twice. */ if (isSymlink) { mode = UnixStat.LINK_FLAG | mode; } if (dir != null && dir.isExisting()) { setTime(ze, dir.getLastModified()); } else { // ZIPs store time with a granularity of 2 seconds, round up setTime(ze, System.currentTimeMillis()); } if (!isSymlink) { ze.setSize(0); ze.setMethod(ZipArchiveEntry.STORED); // This is faintly ridiculous: ze.setCrc(EMPTY_CRC); } ze.setUnixMode(mode); if (!isSymlink) { zOut.addArchiveEntry(ze, createInputStreamSupplier(new ByteArrayInputStream("".getBytes()))); } else { String symlinkDestination = ((SymlinkDestinationSupplier) dir).getSymlinkDestination(); ZipEncoding enc = ZipEncodingHelper.getZipEncoding(encodingToUse); final byte[] bytes = enc.encode(symlinkDestination).array(); ze.setMethod(ZipArchiveEntry.DEFLATED); zOut.addArchiveEntry(ze, createInputStreamSupplier(new ByteArrayInputStream(bytes))); } } }
From source file:org.dataconservancy.packaging.tool.impl.ZipArchiveStreamFactory.java
public ZipArchiveEntry newArchiveEntry(String name, long sizeBytes, FileTime created, FileTime lastModified, int unixPermissions, long crc) { ZipArchiveEntry zipArxEntry = new ZipArchiveEntry(name); zipArxEntry.setSize(sizeBytes);//from ww w.jav a2s . co m zipArxEntry.setUnixMode(unixPermissions); zipArxEntry.setLastModifiedTime(lastModified); zipArxEntry.setCreationTime(created); zipArxEntry.setCrc(crc); return zipArxEntry; }
From source file:org.eclipse.jgit.archive.ZipFormat.java
public void putEntry(ArchiveOutputStream out, String path, FileMode mode, ObjectLoader loader) throws IOException { // ZipArchiveEntry detects directories by checking // for '/' at the end of the filename. if (path.endsWith("/") && mode != FileMode.TREE) //$NON-NLS-1$ throw new IllegalArgumentException( MessageFormat.format(ArchiveText.get().pathDoesNotMatchMode, path, mode)); if (!path.endsWith("/") && mode == FileMode.TREE) //$NON-NLS-1$ path = path + "/"; //$NON-NLS-1$ final ZipArchiveEntry entry = new ZipArchiveEntry(path); if (mode == FileMode.TREE) { out.putArchiveEntry(entry);// w ww. j a v a 2 s . c o m out.closeArchiveEntry(); return; } if (mode == FileMode.REGULAR_FILE) { // ok } else if (mode == FileMode.EXECUTABLE_FILE || mode == FileMode.SYMLINK) { entry.setUnixMode(mode.getBits()); } else { // Unsupported mode (e.g., GITLINK). throw new IllegalArgumentException(MessageFormat.format(ArchiveText.get().unsupportedMode, mode)); } entry.setSize(loader.getSize()); out.putArchiveEntry(entry); loader.copyTo(out); out.closeArchiveEntry(); }