示例#1
0
  /**
   * Test of compressPathToZip method, of class ZipManager.
   *
   * @throws Exception
   */
  @Test
  public void testCompressPathToZip() throws Exception {
    File path = new File(mavenTargetDirectoryRule.getResourceTestDirFile(), "ZipSample");
    File outfile = new File(tempDir, "testCompressPathToZip.zip");
    ZipUtil.compressPathToZip(path, outfile);
    ZipFile zipFile = new ZipFile(outfile, CharEncoding.UTF_8);
    try {
      Enumeration<? extends ZipEntry> entries = zipFile.getEntries();
      assertThat(zipFile.getEncoding(), is(CharEncoding.UTF_8));
      int nbEntries = 0;
      while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        nbEntries++;
      }
      assertThat(nbEntries, is(5));
      assertThat(zipFile.getEntry("ZipSample/simple.txt"), is(notNullValue()));
      assertThat(zipFile.getEntry("ZipSample/level1/simple.txt"), is(notNullValue()));
      assertThat(zipFile.getEntry("ZipSample/level1/level2b/simple.txt"), is(notNullValue()));
      assertThat(zipFile.getEntry("ZipSample/level1/level2a/simple.txt"), is(notNullValue()));

      ZipEntry accentuatedEntry =
          zipFile.getEntry("ZipSample/level1/level2a/s\u00efmplifi\u00e9.txt");
      if (accentuatedEntry == null) {
        accentuatedEntry =
            zipFile.getEntry(
                "ZipSample/level1/level2a/"
                    + new String("sïmplifié.txt".getBytes("UTF-8"), Charset.defaultCharset()));
      }
      assertThat(accentuatedEntry, is(notNullValue()));
      assertThat(zipFile.getEntry("ZipSample/level1/level2c/"), is(nullValue()));
    } finally {
      zipFile.close();
    }
  }
示例#2
0
 /**
  * Test of extract method, of class ZipManager.
  *
  * @throws Exception
  */
 @Test
 public void testExtract() throws Exception {
   File source = new File(mavenTargetDirectoryRule.getResourceTestDirFile(), "testExtract.zip");
   File dest = new File(tempDir, "extract");
   dest.mkdirs();
   ZipUtil.extract(source, dest);
   assertThat(dest, is(notNullValue()));
 }
示例#3
0
 /**
  * Test of getNbFiles method, of class ZipManager.
  *
  * @throws Exception
  */
 @Test
 public void testGetNbFiles() throws Exception {
   File path = new File(mavenTargetDirectoryRule.getResourceTestDirFile(), "ZipSample");
   File outfile = new File(tempDir, "testGetNbFiles.zip");
   ZipUtil.compressPathToZip(path, outfile);
   assertThat(outfile, is(notNullValue()));
   assertThat(outfile.exists(), is(true));
   assertThat(outfile.isFile(), is(true));
   int result = ZipUtil.getNbFiles(outfile);
   assertThat(result, is(5));
 }
示例#4
0
 /**
  * Test of extract method, of class ZipManager.
  *
  * @throws Exception
  */
 @Test
 public void testExtractTargz() throws Exception {
   File source = new File(mavenTargetDirectoryRule.getResourceTestDirFile(), "testExtract.tar.gz");
   File dest = new File(tempDir, "extract-tar");
   dest.mkdirs();
   ZipUtil.extract(source, dest);
   assertThat(dest, is(notNullValue()));
   File uncompressedDir = new File(dest, "ZipSample");
   assertThat(uncompressedDir.exists(), is(true));
   assertThat(uncompressedDir.isDirectory(), is(true));
   assertThat(uncompressedDir.list().length, is(2));
 }
示例#5
0
 @Before
 public void setUpClass() throws Exception {
   tempDir = new File(mavenTargetDirectoryRule.getBuildDirFile(), "zipdir");
   tempDir.mkdirs();
 }