Search in sources :

Example 66 with ZipInputStream

use of java.util.zip.ZipInputStream in project bazel by bazelbuild.

the class AndroidResourceValidatorAction method unpackZip.

private static void unpackZip(Path mergedResources, Path expandedOut) throws IOException {
    byte[] buffer = new byte[4096];
    try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(mergedResources)))) {
        ZipEntry z = zis.getNextEntry();
        while (z != null) {
            String entryName = z.getName();
            Path outputPath = expandedOut.resolve(entryName);
            Files.createDirectories(outputPath.getParent());
            try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputPath))) {
                int count = zis.read(buffer);
                while (count != -1) {
                    out.write(buffer, 0, count);
                    count = zis.read(buffer);
                }
            }
            z = zis.getNextEntry();
        }
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 67 with ZipInputStream

use of java.util.zip.ZipInputStream in project gocd by gocd.

the class CommandRepositoryInitializerTest method setUp.

@Before
public void setUp() {
    serverHealthService = mock(ServerHealthService.class);
    systemEnvironment = mock(SystemEnvironment.class);
    zipUtil = mock(ZipUtil.class);
    zipInputStream = mock(ZipInputStream.class);
    when(systemEnvironment.get(SystemEnvironment.VERSION_FILE_IN_DEFAULT_COMMAND_REPOSITORY)).thenReturn("version.txt");
    CommandRepositoryInitializer initializer = new CommandRepositoryInitializer(systemEnvironment, zipUtil, serverHealthService);
    spy = spy(initializer);
    tempFiles = new TempFiles();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ZipInputStream(java.util.zip.ZipInputStream) ZipUtil(com.thoughtworks.go.util.ZipUtil) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) TempFiles(com.thoughtworks.go.util.TempFiles) Before(org.junit.Before)

Example 68 with ZipInputStream

use of java.util.zip.ZipInputStream in project buck by facebook.

the class ZipStepTest method timesAreSanitized.

@Test
public void timesAreSanitized() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    // Create a zip file with a file and a directory.
    Path toZip = tmp.newFolder("zipdir");
    Files.createDirectories(toZip.resolve("child"));
    Files.createFile(toZip.resolve("child/file.txt"));
    Path outputZip = parent.resolve("output.zip");
    ZipStep step = new ZipStep(filesystem, outputZip, ImmutableSet.of(), false, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());
    // Iterate over each of the entries, expecting to see all zeros in the time fields.
    assertTrue(Files.exists(outputZip));
    Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
    try (ZipInputStream is = new ZipInputStream(new FileInputStream(outputZip.toFile()))) {
        for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
            assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime()));
        }
    }
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) Date(java.util.Date) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 69 with ZipInputStream

use of java.util.zip.ZipInputStream in project buck by facebook.

the class ZipStepTest method zipWithEmptyDir.

@Test
public void zipWithEmptyDir() throws IOException {
    Path parent = tmp.newFolder("zipstep");
    Path out = parent.resolve("output.zip");
    tmp.newFolder("zipdir");
    tmp.newFolder("zipdir/foo/");
    tmp.newFolder("zipdir/bar/");
    ZipStep step = new ZipStep(filesystem, Paths.get("zipstep/output.zip"), ImmutableSet.of(), true, ZipCompressionLevel.DEFAULT_COMPRESSION_LEVEL, Paths.get("zipdir"));
    assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode());
    try (Zip zip = new Zip(out, false)) {
        assertEquals(ImmutableSet.of("", "foo/", "bar/"), zip.getDirNames());
    }
    // (e.g. installing an .ipa over the air in iOS 9.1)
    try (ZipInputStream is = new ZipInputStream(new FileInputStream(out.toFile()))) {
        for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
            assertEquals(entry.getName(), ZipEntry.STORED, entry.getMethod());
        }
    }
}
Also used : Path(java.nio.file.Path) Zip(com.facebook.buck.testutil.Zip) ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 70 with ZipInputStream

use of java.util.zip.ZipInputStream in project translationstudio8 by heartsome.

the class CommonFunction method upZipFile.

public static String upZipFile(String zipFile, String baseDir) throws IOException {
    File f = new File(zipFile);
    if (baseDir == null) {
        baseDir = f.getPath() + "_files";
    }
    ZipInputStream zis = new ZipInputStream(new FileInputStream(f));
    ZipEntry ze;
    byte[] buf = new byte[1024];
    while ((ze = zis.getNextEntry()) != null) {
        File outFile = getRealFileName(baseDir, ze.getName());
        FileOutputStream os = new FileOutputStream(outFile);
        int readLen = 0;
        while ((readLen = zis.read(buf, 0, 1024)) != -1) {
            os.write(buf, 0, readLen);
        }
        os.close();
    }
    zis.close();
    return baseDir;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)968 ZipEntry (java.util.zip.ZipEntry)762 IOException (java.io.IOException)355 File (java.io.File)319 FileInputStream (java.io.FileInputStream)316 InputStream (java.io.InputStream)203 FileOutputStream (java.io.FileOutputStream)198 ByteArrayInputStream (java.io.ByteArrayInputStream)190 ByteArrayOutputStream (java.io.ByteArrayOutputStream)138 BufferedInputStream (java.io.BufferedInputStream)127 ZipOutputStream (java.util.zip.ZipOutputStream)91 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)80 OutputStream (java.io.OutputStream)67 URL (java.net.URL)58 Path (java.nio.file.Path)58 FileNotFoundException (java.io.FileNotFoundException)56 HashMap (java.util.HashMap)56 BufferedOutputStream (java.io.BufferedOutputStream)54 ZipFile (java.util.zip.ZipFile)43