use of net.sf.mzmine.util.StreamCopy in project mzmine2 by mzmine.
the class ProjectSavingTask method saveConfiguration.
/**
* Save the configuration file.
*
* @throws java.io.IOException
*/
private void saveConfiguration(ZipOutputStream zipStream) throws IOException {
logger.info("Saving configuration file");
currentSavedObjectName = "configuration";
zipStream.putNextEntry(new ZipEntry(CONFIG_FILENAME));
try {
File tempConfigFile = File.createTempFile("mzmineconfig", ".tmp");
MZmineCore.getConfiguration().saveConfiguration(tempConfigFile);
FileInputStream fileStream = new FileInputStream(tempConfigFile);
StreamCopy copyMachine = new StreamCopy();
copyMachine.copy(fileStream, zipStream);
fileStream.close();
tempConfigFile.delete();
} catch (Exception e) {
e.printStackTrace();
logger.warning("Could not save configuration" + ExceptionUtils.exceptionToString(e));
}
}
use of net.sf.mzmine.util.StreamCopy in project mzmine2 by mzmine.
the class ProjectOpeningTask method loadConfiguration.
/**
* Load the configuration file from the project zip file
*/
private void loadConfiguration(InputStream is) throws IOException {
logger.info("Loading configuration file");
currentLoadedObjectName = "Configuration";
File tempConfigFile = File.createTempFile("mzmineconfig", ".tmp");
FileOutputStream fileStream = new FileOutputStream(tempConfigFile);
copyMachine = new StreamCopy();
copyMachine.copy(is, fileStream);
fileStream.close();
try {
MZmineCore.getConfiguration().loadConfiguration(tempConfigFile);
} catch (Exception e) {
logger.warning("Could not load configuration from the project: " + ExceptionUtils.exceptionToString(e));
}
tempConfigFile.delete();
}
use of net.sf.mzmine.util.StreamCopy in project mzmine2 by mzmine.
the class ZipReadTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
// Update task status
setStatus(TaskStatus.PROCESSING);
logger.info("Started opening compressed file " + file);
try {
// Name of the uncompressed file
String newName = file.getName();
if (newName.toLowerCase().endsWith(".zip") || newName.toLowerCase().endsWith(".gz")) {
newName = FilenameUtils.removeExtension(newName);
}
// Create decompressing stream
FileInputStream fis = new FileInputStream(file);
InputStream is;
long decompressedSize = 0;
switch(fileType) {
case ZIP:
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry = zis.getNextEntry();
newName = entry.getName();
decompressedSize = entry.getSize();
if (decompressedSize < 0)
decompressedSize = 0;
is = zis;
break;
case GZIP:
is = new GZIPInputStream(fis);
// Ballpark a
decompressedSize = (long) (file.length() * 1.5);
// progress
if (decompressedSize < 0)
decompressedSize = 0;
break;
default:
setErrorMessage("Cannot decompress file type: " + fileType);
setStatus(TaskStatus.ERROR);
return;
}
tmpDir = Files.createTempDir();
tmpFile = new File(tmpDir, newName);
logger.finest("Decompressing to file " + tmpFile);
tmpFile.deleteOnExit();
tmpDir.deleteOnExit();
FileOutputStream ous = new FileOutputStream(tmpFile);
// Decompress the contents
copy = new StreamCopy();
copy.copy(is, ous, decompressedSize);
// Close the streams
is.close();
ous.close();
if (isCanceled())
return;
// Find the type of the decompressed file
RawDataFileType fileType = RawDataFileTypeDetector.detectDataFileType(tmpFile);
logger.finest("File " + tmpFile + " type detected as " + fileType);
if (fileType == null) {
setErrorMessage("Could not determine the file type of file " + newName);
setStatus(TaskStatus.ERROR);
return;
}
// Run the import module on the decompressed file
RawDataFileWriter newMZmineFile = MZmineCore.createNewFile(newName);
decompressedOpeningTask = RawDataImportModule.createOpeningTask(fileType, project, tmpFile, newMZmineFile);
if (decompressedOpeningTask == null) {
setErrorMessage("File type " + fileType + " of file " + newName + " is not supported.");
setStatus(TaskStatus.ERROR);
return;
}
// Run the underlying task
decompressedOpeningTask.run();
// Delete the temporary folder
tmpFile.delete();
tmpDir.delete();
if (isCanceled())
return;
} catch (Throwable e) {
e.printStackTrace();
logger.log(Level.SEVERE, "Could not open file " + file.getPath(), e);
setErrorMessage(ExceptionUtils.exceptionToString(e));
setStatus(TaskStatus.ERROR);
return;
}
logger.info("Finished opening compressed file " + file);
// Update task status
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.util.StreamCopy in project mzmine2 by mzmine.
the class ProjectOpeningTask method loadScansFile.
private void loadScansFile(InputStream is, String fileID, String fileName) throws IOException {
logger.info("Loading scans data #" + fileID + ": " + fileName);
currentLoadedObjectName = fileName + " scan data";
final File tempFile = RawDataFileImpl.createNewDataPointsFile();
final FileOutputStream os = new FileOutputStream(tempFile);
copyMachine = new StreamCopy();
copyMachine.copy(is, os);
os.close();
scanFilesIDMap.put(fileID, tempFile);
}
Aggregations