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

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

Introduction

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

Prototype

public int getPlatform() 

Source Link

Document

Platform specification to put into the "version made by" part of the central file header.

Usage

From source file:com.android.tradefed.util.ZipUtil2.java

/**
 * A util method to apply unix mode from {@link ZipArchiveEntry} to the created local file
 * system entry if necessary/*  www.  j a  va 2  s .  c  o  m*/
 * @param entry the entry inside zipfile (potentially contains mode info)
 * @param localFile the extracted local file entry
 * @throws IOException
 */
private static void applyUnixModeIfNecessary(ZipArchiveEntry entry, File localFile) throws IOException {
    if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
        Files.setPosixFilePermissions(localFile.toPath(), FileUtil.unixModeToPosix(entry.getUnixMode()));
    } else {
        CLog.i("Entry does not contain Unix mode info: %s", entry.getName());
    }
}

From source file:org.codehaus.mojo.unix.maven.zip.ZipPackageTest.java

private void assertFile(ZipFile file, ZipArchiveEntry entry, String name, int size, LocalDateTime time,
        String content, UnixFileMode mode) throws IOException {
    InputStream in = file.getInputStream(entry);

    assertFalse(name + " should be file", entry.isDirectory());
    assertEquals(name + ", name", name, entry.getName());
    assertEquals(name + ", timestamp", time, new LocalDateTime(entry.getTime()));
    // wtf: http://vimalathithen.blogspot.no/2006/06/using-zipentrygetsize.html
    // assertEquals( name + ", size", size, entry.getSize() );

    byte[] bytes = new byte[1000];
    assertEquals(size, in.read(bytes, 0, bytes.length));
    assertEquals(content, new String(bytes, 0, size, charset));

    assertEquals(ZipArchiveEntry.PLATFORM_UNIX, entry.getPlatform());
    assertEquals(name + ", mode", mode.toString(), UnixFileMode.fromInt(entry.getUnixMode()).toString());
}

From source file:org.everit.osgi.dev.maven.util.FileManager.java

private static void setPermissionsOnFile(final File file, final ZipArchiveEntry entry) throws IOException {
    if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_FAT) {
        return;/*from  w ww . j a v  a 2 s .c  o  m*/
    }
    int unixPermissions = entry.getUnixMode();

    Set<PosixFilePermission> perms = new HashSet<>();

    if ((unixPermissions & OWNER_EXECUTE_BITMASK) > 0) {
        perms.add(PosixFilePermission.OWNER_EXECUTE);
    }

    if ((unixPermissions & GROUP_EXECUTE_BITMASK) > 0) {
        perms.add(PosixFilePermission.GROUP_EXECUTE);
    }

    if ((unixPermissions & OTHERS_EXECUTE_BITMASK) > 0) {
        perms.add(PosixFilePermission.OTHERS_EXECUTE);
    }

    if ((unixPermissions & OWNER_READ_BITMASK) > 0) {
        perms.add(PosixFilePermission.OWNER_READ);
    }

    if ((unixPermissions & GROUP_READ_BITMASK) > 0) {
        perms.add(PosixFilePermission.GROUP_READ);
    }

    if ((unixPermissions & OTHERS_READ_BITMASK) > 0) {
        perms.add(PosixFilePermission.OTHERS_READ);
    }

    if ((unixPermissions & OWNER_WRITE_BITMASK) > 0) {
        perms.add(PosixFilePermission.OWNER_WRITE);
    }

    if ((unixPermissions & GROUP_WRITE_BITMASK) > 0) {
        perms.add(PosixFilePermission.GROUP_WRITE);
    }

    if ((unixPermissions & OTHERS_WRITE_BITMASK) > 0) {
        perms.add(PosixFilePermission.OTHERS_WRITE);
    }

    Path path = file.toPath();
    if (path.getFileSystem().supportedFileAttributeViews().contains("posix")) {
        Files.setPosixFilePermissions(path, perms);
    } else {
        setPermissionsOnFileInNonPosixSystem(file, perms);
    }
}

From source file:org.springframework.boot.gradle.tasks.bundling.AbstractBootArchiveTests.java

@Test
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
    this.task.setMainClassName("com.example.Main");
    this.task.setMetadataCharset("UTF-8");
    File classpathFolder = this.temp.newFolder();
    File resource = new File(classpathFolder, "some-resource.xml");
    resource.getParentFile().mkdirs();/* w ww  .ja  va 2 s.  c  o m*/
    resource.createNewFile();
    this.task.classpath(classpathFolder);
    this.task.execute();
    File archivePath = this.task.getArchivePath();
    try (ZipFile zip = new ZipFile(archivePath)) {
        Enumeration<ZipArchiveEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            assertThat(entry.getPlatform()).isEqualTo(ZipArchiveEntry.PLATFORM_UNIX);
            assertThat(entry.getGeneralPurposeBit().usesUTF8ForNames()).isTrue();
        }
    }
}

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

@Test
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
    this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
    File source = this.testJarFile.getFile();
    File dest = this.temporaryFolder.newFile("dest.jar");
    Repackager repackager = new Repackager(source);
    repackager.repackage(dest, NO_LIBRARIES);
    try (ZipFile zip = new ZipFile(dest)) {
        Enumeration<ZipArchiveEntry> entries = zip.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry entry = entries.nextElement();
            assertThat(entry.getPlatform()).isEqualTo(ZipArchiveEntry.PLATFORM_UNIX);
            assertThat(entry.getGeneralPurposeBit().usesUTF8ForNames()).isTrue();
        }/*w  ww. j a v  a  2  s. co  m*/
    }
}