Пример #1
0
 @Override
 public int execute(ExecutionContext context) {
   try {
     extractZipFile(
         pathToZipFile, pathToDestinationDirectory, filesToExtract, overwriteExistingFiles);
   } catch (IOException e) {
     e.printStackTrace(context.getStdErr());
     return 1;
   }
   return 0;
 }
Пример #2
0
 @Test
 public void testExtractZipFile() throws IOException {
   ImmutableSet<String> filesToExtract = ImmutableSet.of();
   File extractFolder = tmpFolder.newFolder();
   UnzipStep.extractZipFile(
       zipFile.getAbsolutePath(), extractFolder.getAbsolutePath(), filesToExtract, false);
   assertTrue(new File(extractFolder.getAbsolutePath() + "/1.bin").exists());
   File bin2 = new File(extractFolder.getAbsolutePath() + "/subdir/2.bin");
   assertTrue(bin2.exists());
   assertTrue(new File(extractFolder.getAbsolutePath() + "/emptydir").isDirectory());
   try (FileInputStream input = new FileInputStream(bin2)) {
     byte[] buffer = new byte[DUMMY_FILE_CONTENTS.length];
     int bytesRead = input.read(buffer, 0, DUMMY_FILE_CONTENTS.length);
     assertEquals(DUMMY_FILE_CONTENTS.length, bytesRead);
     for (int i = 0; i < DUMMY_FILE_CONTENTS.length; i++) {
       assertEquals(DUMMY_FILE_CONTENTS[i], buffer[i]);
     }
   }
 }