public void extractionProgress(String identifier, float percentageDone) { int trackableProgress = Math.round(percentageDone * range); if (trackableProgress > lastProgressUpdate) { parent.extractionProgress(identifier, trackableProgress); lastProgressUpdate = trackableProgress; } }
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"); } }
public EntryObserver(ExtractionObserver parent, float divisions) { this.parent = parent; this.range = Math.round(((float) parent.getRange()) / divisions); }