List of usage examples for org.apache.commons.compress.archivers.zip ZipUtil dosToJavaTime
public static long dosToJavaTime(long dosTime)
From source file:com.facebook.buck.util.zip.ZipScrubberTest.java
@Test public void modificationTimes() throws Exception { // Create a dummy ZIP file. ByteArrayOutputStream bytesOutputStream = new ByteArrayOutputStream(); try (ZipOutputStream out = new ZipOutputStream(bytesOutputStream)) { ZipEntry entry = new ZipEntry("file1"); byte[] data = "data1".getBytes(Charsets.UTF_8); entry.setSize(data.length);/*from w w w . j a v a2s. c om*/ out.putNextEntry(entry); out.write(data); out.closeEntry(); entry = new ZipEntry("file2"); data = "data2".getBytes(Charsets.UTF_8); entry.setSize(data.length); out.putNextEntry(entry); out.write(data); out.closeEntry(); } byte[] bytes = bytesOutputStream.toByteArray(); // Execute the zip scrubber step. ZipScrubber.scrubZipBuffer(bytes.length, ByteBuffer.wrap(bytes)); // Iterate over each of the entries, expecting to see all zeros in the time fields. Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new ByteArrayInputStream(bytes))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); } } }
From source file:com.facebook.buck.zip.ZipScrubberStepIntegrationTest.java
@Test public void modificationTimes() throws Exception { // Create a dummy ZIP file. Path zip = tmp.newFile("output.zip"); try (ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(zip))) { ZipEntry entry = new ZipEntry("file1"); byte[] data = "data1".getBytes(Charsets.UTF_8); entry.setSize(data.length);// w w w . j av a 2s. c o m out.putNextEntry(entry); out.write(data); out.closeEntry(); entry = new ZipEntry("file2"); data = "data2".getBytes(Charsets.UTF_8); entry.setSize(data.length); out.putNextEntry(entry); out.write(data); out.closeEntry(); } // Execute the zip scrubber step. ExecutionContext executionContext = TestExecutionContext.newInstance(); ZipScrubberStep step = new ZipScrubberStep(new ProjectFilesystem(tmp.getRoot()), Paths.get("output.zip")); assertEquals(0, step.execute(executionContext).getExitCode()); // Iterate over each of the entries, expecting to see all zeros in the time fields. Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(zip.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); } } }
From source file:com.facebook.buck.util.zip.ZipScrubberTest.java
@Test public void modificationTimesExceedShort() throws Exception { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] data = "data1".getBytes(Charsets.UTF_8); try (ZipOutputStream out = new ZipOutputStream(byteArrayOutputStream)) { for (long i = 0; i < Short.MAX_VALUE + 1; i++) { ZipEntry entry = new ZipEntry("file" + i); entry.setSize(data.length);/*ww w . j a v a2s . c o m*/ out.putNextEntry(entry); out.write(data); out.closeEntry(); } } byte[] bytes = byteArrayOutputStream.toByteArray(); ZipScrubber.scrubZipBuffer(bytes.length, ByteBuffer.wrap(bytes)); // Iterate over each of the entries, expecting to see all zeros in the time fields. Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new ByteArrayInputStream(bytes))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); } } }
From source file:com.facebook.buck.android.AndroidAppBundleIntegrationTest.java
@Test public void testAppBundleHaveDeterministicTimestamps() throws IOException { String target = "//apps/sample:app_bundle_1"; ProcessResult result = workspace.runBuckCommand("build", target); result.assertSuccess();// w w w . j a v a2s .c o m // Iterate over each of the entries, expecting to see all zeros in the time fields. Path aab = workspace.getPath( BuildTargetPaths.getGenPath(filesystem, BuildTargetFactory.newInstance(target), "%s.signed.aab")); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(Files.newInputStream(aab))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); } } ZipInspector zipInspector = new ZipInspector(aab); zipInspector.assertFileExists("BundleConfig.pb"); zipInspector.assertFileExists("base/dex/classes.dex"); zipInspector.assertFileExists("base/assets.pb"); zipInspector.assertFileExists("base/resources.pb"); zipInspector.assertFileExists("base/manifest/AndroidManifest.xml"); zipInspector.assertFileExists("base/assets/asset_file.txt"); zipInspector.assertFileExists("base/res/drawable/tiny_black.png"); zipInspector.assertFileExists("base/native.pb"); zipInspector.assertFileExists("base/lib/armeabi-v7a/libnative_cxx_lib.so"); zipInspector.assertFileExists("base/assets/secondary-program-dex-jars/secondary-1.dex.jar"); NativeLibraries nativeLibraries = NativeLibraries.parseFrom(zipInspector.getFileContents("base/native.pb")); assertEquals(3, nativeLibraries.getDirectoryList().size()); for (TargetedNativeDirectory targetedNativeDirectory : nativeLibraries.getDirectoryList()) { assertTrue(targetedNativeDirectory.hasTargeting()); assertTrue(targetedNativeDirectory.getTargeting().hasAbi()); } Assets assets = Assets.parseFrom(zipInspector.getFileContents("base/assets.pb")); for (TargetedAssetsDirectory targetedAssetsDirectory : assets.getDirectoryList()) { assertTrue(targetedAssetsDirectory.hasTargeting()); assertTrue(targetedAssetsDirectory.getTargeting().hasAbi()); } BundleConfig bundleConfig = BundleConfig.parseFrom(zipInspector.getFileContents("BundleConfig.pb")); assertTrue(bundleConfig.hasBundletool()); assertBundletool(bundleConfig.getBundletool()); assertTrue(bundleConfig.hasOptimizations()); assertOptimizations(bundleConfig.getOptimizations()); assertTrue(bundleConfig.hasCompression()); assertCompression(bundleConfig.getCompression()); }
From source file:com.facebook.buck.android.AaptPackageResourcesIntegrationTest.java
@Test public void testAaptPackageIsScrubbed() throws IOException { AssumeAndroidPlatform.assumeSdkIsAvailable(); workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess(); Path aaptOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(MAIN_BUILD_TARGET) .withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), AaptPackageResources.RESOURCE_APK_PATH_FORMAT)); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(aaptOutput.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); }// www. ja v a 2s . c o m } }
From source file:com.facebook.buck.util.zip.ZipScrubberTest.java
@Test public void modificationZip64Times() throws Exception { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] data = "data1".getBytes(Charsets.UTF_8); try (ZipOutputStream out = new ZipOutputStream(byteArrayOutputStream)) { for (long i = 0; i < 2 * Short.MAX_VALUE + 1; i++) { ZipEntry entry = new ZipEntry("file" + i); entry.setSize(data.length);/*from w ww. jav a 2 s. c om*/ out.putNextEntry(entry); out.write(data); out.closeEntry(); } } byte[] bytes = byteArrayOutputStream.toByteArray(); ZipScrubber.scrubZipBuffer(bytes.length, ByteBuffer.wrap(bytes)); // Iterate over each of the entries, expecting to see all zeros in the time fields. Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new ByteArrayInputStream(bytes))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch)); } } }
From source file:com.facebook.buck.java.JarDirectoryStepTest.java
@Test public void timesAreSanitized() throws IOException { Path zipup = folder.newFolder("dir-zip"); // Create a jar file with a file and a directory. Path subdir = zipup.resolve("dir"); Files.createDirectories(subdir); Files.write(subdir.resolve("a.txt"), "cake".getBytes()); Path outputJar = folder.getRoot().resolve("output.jar"); JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(folder.getRoot()), outputJar, ImmutableSet.of(zipup), /* main class */ null, /* manifest file */ null); ExecutionContext context = TestExecutionContext.newInstance(); int returnCode = step.execute(context); assertEquals(0, returnCode);//from www . j av a 2 s . co m // Iterate over each of the entries, expecting to see all zeros in the time fields. assertTrue(Files.exists(outputJar)); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_EPOCH_START)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(outputJar.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime())); } } }
From source file:com.facebook.buck.zip.ZipStepTest.java
@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())); }// www . ja v a 2 s .co m } }
From source file:com.facebook.buck.jvm.java.JarDirectoryStepTest.java
@Test public void timesAreSanitized() throws IOException { Path zipup = folder.newFolder("dir-zip"); // Create a jar file with a file and a directory. Path subdir = zipup.resolve("dir"); Files.createDirectories(subdir); Files.write(subdir.resolve("a.txt"), "cake".getBytes()); Path outputJar = folder.getRoot().resolve("output.jar"); JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(folder.getRoot()), outputJar, ImmutableSortedSet.of(zipup), /* main class */ null, /* manifest file */ null); ExecutionContext context = TestExecutionContext.newInstance(); int returnCode = step.execute(context).getExitCode(); assertEquals(0, returnCode);/* w w w . j a v a2 s . c o m*/ // Iterate over each of the entries, expecting to see all zeros in the time fields. assertTrue(Files.exists(outputJar)); Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(new FileInputStream(outputJar.toFile()))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime())); } } }
From source file:com.facebook.buck.io.ProjectFilesystemTest.java
@Test public void testCreateZipIgnoresMtimes() throws IOException { // Create a empty executable file. Path exe = tmp.newFile("foo"); // Archive it into a zipfile using `ProjectFileSystem.createZip`. Path zipFile = tmp.getRoot().resolve("test.zip"); filesystem.createZip(ImmutableList.of(exe), zipFile, ImmutableMap.of(Paths.get("additional"), "info")); // Iterate over each of the entries, expecting to see all zeros in the time fields. Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME)); try (ZipInputStream is = new ZipInputStream(Files.newInputStream(zipFile))) { for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) { assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime())); }// ww w. j av a2 s .c o m } }