Пример #1
0
      @Override
      public void takeAction(SevenZFile archive, SevenZArchiveEntry entry) throws IOException {
        File outFile = new File(entry.getName());
        if (entry.isDirectory()) {
          if (!outFile.isDirectory() && !outFile.mkdirs()) {
            throw new IOException("Cannot create directory " + outFile);
          }
          System.out.println("created directory " + outFile);
          return;
        }

        System.out.println("extracting to " + outFile);
        File parent = outFile.getParentFile();
        if (parent != null && !parent.exists() && !parent.mkdirs()) {
          throw new IOException("Cannot create " + parent);
        }
        FileOutputStream fos = new FileOutputStream(outFile);
        try {
          final long total = entry.getSize();
          long off = 0;
          while (off < total) {
            int toRead = (int) Math.min(total - off, BUF.length);
            int bytesRead = archive.read(BUF, 0, toRead);
            if (bytesRead < 1) {
              throw new IOException(
                  "reached end of entry "
                      + entry.getName()
                      + " after "
                      + off
                      + " bytes, expected "
                      + total);
            }
            off += bytesRead;
            fos.write(BUF, 0, bytesRead);
          }
        } finally {
          fos.close();
        }
      }
Пример #2
0
 @Override
 public void takeAction(SevenZFile archive, SevenZArchiveEntry entry) {
   System.out.print(entry.getName());
   if (entry.isDirectory()) {
     System.out.print(" dir");
   } else {
     System.out.print(" " + entry.getCompressedSize() + "/" + entry.getSize());
   }
   if (entry.getHasLastModifiedDate()) {
     System.out.print(" " + entry.getLastModifiedDate());
   } else {
     System.out.print(" no last modified date");
   }
   if (!entry.isDirectory()) {
     System.out.println(" " + getContentMethods(entry));
   } else {
     System.out.println("");
   }
 }