コード例 #1
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));
 }
コード例 #2
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();
    }
  }
コード例 #3
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()));
 }
コード例 #4
0
 /**
  * Test of compressStreamToZip method, of class ZipManager.
  *
  * @throws Exception
  */
 @Test
 public void testCompressStreamToZip() throws Exception {
   InputStream inputStream =
       this.getClass().getClassLoader().getResourceAsStream("FrenchScrum.odp");
   String filePathNameToCreate =
       separatorChar + "dir1" + separatorChar + "dir2" + separatorChar + "FrenchScrum.odp";
   File outfile = new File(tempDir, "testCompressStreamToZip.zip");
   ZipUtil.compressStreamToZip(inputStream, filePathNameToCreate, outfile.getPath());
   inputStream.close();
   assertThat(outfile, is(notNullValue()));
   assertThat(outfile.exists(), is(true));
   assertThat(outfile.isFile(), is(true));
   int result = ZipUtil.getNbFiles(outfile);
   assertThat(result, is(1));
   ZipFile zipFile = new ZipFile(outfile);
   assertThat(zipFile.getEntry("/dir1/dir2/FrenchScrum.odp"), is(notNullValue()));
   zipFile.close();
 }
コード例 #5
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));
 }