use of net.sf.mzmine.modules.projectmethods.projectsave.PeakListSaveHandler in project mzmine2 by mzmine.
the class XMLExportTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
// Shall export several files?
boolean substitute = fileName.getPath().contains(plNamePattern);
// Process feature lists
for (int i = 0; i < peakLists.length; i++) {
PeakList peakList = peakLists[i];
File curFile = fileName;
try {
// Filename
if (substitute) {
// Cleanup from illegal filename characters
String cleanPlName = peakList.getName().replaceAll("[^a-zA-Z0-9.-]", "_");
// Substitute
String newFilename = fileName.getPath().replaceAll(Pattern.quote(plNamePattern), cleanPlName);
curFile = new File(newFilename);
}
// Open file
FileWriter writer;
try {
writer = new FileWriter(curFile);
} catch (Exception e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not open file " + curFile + " for writing.");
return;
}
logger.info("Started saving feature list " + peakList.getName());
// write the saving file
FileOutputStream fos = new FileOutputStream(curFile);
OutputStream finalStream = fos;
if (compression) {
@SuppressWarnings("resource") ZipOutputStream zos = new ZipOutputStream(fos);
zos.setLevel(9);
zos.putNextEntry(new ZipEntry(fileName.getName()));
finalStream = zos;
}
Hashtable<RawDataFile, String> dataFilesIDMap = new Hashtable<RawDataFile, String>();
for (RawDataFile file : peakList.getRawDataFiles()) {
dataFilesIDMap.put(file, file.getName());
}
PeakListSaveHandler peakListSaveHandler = new PeakListSaveHandler(finalStream, dataFilesIDMap);
peakListSaveHandlers[i] = peakListSaveHandler;
peakListSaveHandler.savePeakList(peakList);
finalStream.close();
} catch (Exception e) {
/* we may already have set the status to CANCELED */
if (getStatus() == TaskStatus.PROCESSING) {
setStatus(TaskStatus.ERROR);
}
setErrorMessage(e.toString());
e.printStackTrace();
return;
}
logger.info("Finished saving " + peakList.getName());
setStatus(TaskStatus.FINISHED);
}
}
Aggregations