Example usage for org.apache.commons.compress.archivers.zip UnixStat DEFAULT_FILE_PERM

List of usage examples for org.apache.commons.compress.archivers.zip UnixStat DEFAULT_FILE_PERM

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.zip UnixStat DEFAULT_FILE_PERM.

Prototype

int DEFAULT_FILE_PERM

To view the source code for org.apache.commons.compress.archivers.zip UnixStat DEFAULT_FILE_PERM.

Click Source Link

Document

Default permissions for plain files.

Usage

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);/*from  ww w . ja  va2 s .c om*/
        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.springframework.boot.gradle.tasks.bundling.BootZipCopyAction.java

private void writeClass(ZipArchiveEntry entry, ZipInputStream in, ZipArchiveOutputStream out)
        throws IOException {
    prepareEntry(entry, UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
    out.putArchiveEntry(entry);//w w  w.  j a  v a 2s  . co  m
    byte[] buffer = new byte[4096];
    int read;
    while ((read = in.read(buffer)) > 0) {
        out.write(buffer, 0, read);
    }
    out.closeArchiveEntry();
}

From source file:org.springframework.boot.loader.tools.JarWriter.java

/**
 * Perform the actual write of a {@link JarEntry}. All other write methods delegate to
 * this one.//w  ww . j  av a2s  .  c om
 * @param entry the entry to write
 * @param entryWriter the entry writer or {@code null} if there is no content
 * @param unpackHandler handles possible unpacking for the entry
 * @throws IOException in case of I/O errors
 */
private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler)
        throws IOException {
    String parent = entry.getName();
    if (parent.endsWith("/")) {
        parent = parent.substring(0, parent.length() - 1);
        entry.setUnixMode(UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM);
    } else {
        entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
    }
    if (parent.lastIndexOf('/') != -1) {
        parent = parent.substring(0, parent.lastIndexOf('/') + 1);
        if (!parent.isEmpty()) {
            writeEntry(new JarArchiveEntry(parent), null, unpackHandler);
        }
    }

    if (this.writtenEntries.add(entry.getName())) {
        entryWriter = addUnpackCommentIfNecessary(entry, entryWriter, unpackHandler);
        this.jarOutput.putArchiveEntry(entry);
        if (entryWriter != null) {
            entryWriter.write(this.jarOutput);
        }
        this.jarOutput.closeArchiveEntry();
    }
}