Esempio n. 1
0
  public void extractToFiles(
      File outDir, ExtractionObserver obs, boolean allowCancel, boolean convertData)
      throws IOException {
    cancelSignalled = false;

    if (outDir.exists() && !outDir.isDirectory()) {
      throw new IllegalArgumentException(outDir.getAbsolutePath() + " is not a directory");
    }

    LodEntry currentEntry;

    if (!outDir.exists()) {
      outDir.mkdirs();
      obs.directoryCreated(outDir);
    }

    while (entriesToExtractIterator.hasNext() && !(allowCancel && cancelSignalled)) {
      currentEntry = (LodEntry) entriesToExtractIterator.next();
      String filename = currentEntry.getFileName();

      FormatConverter converter = null;
      if (convertData) converter = currentEntry.getFormatConverter();
      else {
        converter = new NullFormatConverter();
        filename = filename + ".raw";
      }

      String identifier = currentEntry.getName();

      if (converter.requiresMultipleStreams()) {
        // IMPLEMENT: replace basefilename
        String baseFilename = filename;
        String[] filenames = converter.getSuggestedFilenames(baseFilename);
        OutputStream[] outputStreamArray = new OutputStream[filenames.length];
        for (int i = 0; i < outputStreamArray.length; ++i) {
          outputStreamArray[i] =
              new BufferedOutputStream(new FileOutputStream(new File(outDir, filenames[i])));
        }
        converter.setDestinationOutputStreamsForNewFormat(outputStreamArray, currentEntry);
      } else {
        converter.setDestinationOutputStreamForNewFormat(
            new BufferedOutputStream(new FileOutputStream(new File(outDir, filename))),
            currentEntry);
      }

      Extractor extractor = new Extractor();

      extractor.convert(
          identifier,
          currentEntry.getData(),
          converter.getSourceOutputStreamForOldFormat(),
          (null != obs) ? new EntryObserver(obs, total) : null,
          allowCancel);

      if (null != obs) {
        obs.extractionProgress(identifier, counter++ / total);
      }
    }

    if (obs != null) {
      obs.extractionFinished("Done");
    }
  }
Esempio n. 2
0
 public boolean cancelJob() {
   cancelSignalled = true;
   return extractor.cancelExtraction();
 }