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();
}
}
}
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();
}
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()));
}
}
}
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());
}
}
}
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;
}
Aggregations