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

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

Introduction

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

Prototype

int PLATFORM_UNIX

To view the source code for org.apache.commons.compress.archivers.zip ZipArchiveEntry PLATFORM_UNIX.

Click Source Link

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//from  w ww.  j  ava2  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.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();//from   w w w  .  ja va  2  s .  co  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();
        }//from  w ww .j  av  a  2s.  c o m
    }
}