Example usage for org.apache.commons.compress.archivers.zip ZipArchiveEntry setExternalAttributes

List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry setExternalAttributes

Introduction

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

Prototype

public void setExternalAttributes(long value) 

Source Link

Document

Sets the external file attributes.

Usage

From source file:at.spardat.xma.xdelta.JarDelta.java

/**
 * Entry to new name.//from w w w.j av  a2 s  .  c o  m
 *
 * @param source the source
 * @param name the name
 * @return the zip archive entry
 * @throws ZipException the zip exception
 */
public static ZipArchiveEntry entryToNewName(ZipArchiveEntry source, String name) throws ZipException {
    if (source.getName().equals(name))
        return new ZipArchiveEntry(source);
    ZipArchiveEntry ret = new ZipArchiveEntry(name);
    byte[] extra = source.getExtra();
    if (extra != null) {
        ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
    } else {
        ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true)));
    }
    ret.setInternalAttributes(source.getInternalAttributes());
    ret.setExternalAttributes(source.getExternalAttributes());
    ret.setExtraFields(source.getExtraFields(true));
    ret.setCrc(source.getCrc());
    ret.setMethod(source.getMethod());
    ret.setSize(source.getSize());
    return ret;
}

From source file:at.spardat.xma.xdelta.JarPatcher.java

/**
 * Entry to new name./* w  w w  .j  ava  2s  .c  om*/
 *
 * @param source the source
 * @param name the name
 * @return the zip archive entry
 * @throws ZipException the zip exception
 */
private ZipArchiveEntry copyEntry(ZipArchiveEntry source) throws ZipException {
    ZipArchiveEntry ret = new ZipArchiveEntry(source.getName());
    byte[] extra = source.getExtra();
    if (extra != null) {
        ret.setExtraFields(ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
    } else {
        ret.setExtra(ExtraFieldUtils.mergeLocalFileDataData(source.getExtraFields(true)));
    }
    ret.setInternalAttributes(source.getInternalAttributes());
    ret.setExternalAttributes(source.getExternalAttributes());
    ret.setExtraFields(source.getExtraFields(true));
    return ret;
}

From source file:com.facebook.buck.util.unarchive.UnzipTest.java

@Test
public void testExtractBrokenSymlinkWithOwnerExecutePermissions() throws InterruptedException, IOException {
    assumeThat(Platform.detect(), Matchers.is(Matchers.not(Platform.WINDOWS)));

    // Create a simple zip archive using apache's commons-compress to store executable info.
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
        ZipArchiveEntry entry = new ZipArchiveEntry("link.txt");
        entry.setUnixMode((int) MostFiles.S_IFLNK);
        String target = "target.txt";
        entry.setSize(target.getBytes(Charsets.UTF_8).length);
        entry.setMethod(ZipEntry.STORED);

        // Mark the file as being executable.
        Set<PosixFilePermission> filePermissions = ImmutableSet.of(PosixFilePermission.OWNER_EXECUTE);

        long externalAttributes = entry.getExternalAttributes()
                + (MorePosixFilePermissions.toMode(filePermissions) << 16);
        entry.setExternalAttributes(externalAttributes);

        zip.putArchiveEntry(entry);/*from w w w .  j a v  a2s .c o m*/
        zip.write(target.getBytes(Charsets.UTF_8));
        zip.closeArchiveEntry();
    }

    Path extractFolder = tmpFolder.newFolder();

    ArchiveFormat.ZIP.getUnarchiver().extractArchive(new DefaultProjectFilesystemFactory(),
            zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE);
    Path link = extractFolder.toAbsolutePath().resolve("link.txt");
    assertTrue(Files.isSymbolicLink(link));
    assertThat(Files.readSymbolicLink(link).toString(), Matchers.equalTo("target.txt"));
}

From source file:org.fabrician.maven.plugins.CompressUtils.java

private static ArchiveEntry createArchiveEntry(ArchiveEntry entry, OutputStream out, String alternateBaseDir)
        throws IOException {
    String substitutedName = substituteAlternateBaseDir(entry, alternateBaseDir);
    if (out instanceof TarArchiveOutputStream) {
        TarArchiveEntry newEntry = new TarArchiveEntry(substitutedName);
        newEntry.setSize(entry.getSize());
        newEntry.setModTime(entry.getLastModifiedDate());

        if (entry instanceof TarArchiveEntry) {
            TarArchiveEntry old = (TarArchiveEntry) entry;
            newEntry.setSize(old.getSize());
            newEntry.setIds(old.getUserId(), old.getGroupId());
            newEntry.setNames(old.getUserName(), old.getGroupName());
        }// w w w  . j  a v a  2s  .  c  o  m
        return newEntry;
    } else if (entry instanceof ZipArchiveEntry) {
        ZipArchiveEntry old = (ZipArchiveEntry) entry;
        ZipArchiveEntry zip = new ZipArchiveEntry(substitutedName);
        zip.setInternalAttributes(old.getInternalAttributes());
        zip.setExternalAttributes(old.getExternalAttributes());
        zip.setExtraFields(old.getExtraFields(true));
        return zip;
    } else {
        return new ZipArchiveEntry(substitutedName);
    }
}