/** {@inheritDoc} */ @Override public void cancel() { this.canceled = true; if (parser != null) { parser.cancel(); } }
/** {@inheritDoc} */ @SuppressWarnings("null") @Override public RawDataFile execute() throws MSDKException { String osName = System.getProperty("os.name").toUpperCase(); if (!osName.contains("WINDOWS")) { throw new MSDKException("Native data format import only works on MS Windows"); } logger.info("Started parsing file " + sourceFile); try { // Decompress the thermo raw dump executable to a temporary folder File tempFolder = Files.createTempDirectory("msdk").toFile(); tempFolder.deleteOnExit(); InputStream dumpArchive = this.getClass().getClassLoader().getResourceAsStream("thermorawdump.zip"); if (dumpArchive == null) throw new MSDKException("Failed to load the thermorawdump.zip archive from the MSDK jar"); ZipUtils.extractStreamToFolder(dumpArchive, tempFolder); // Path to the rawdump executable File rawDumpPath = new File(tempFolder, "ThermoRawDump.exe"); if (!rawDumpPath.canExecute()) throw new MSDKException("Cannot execute program " + rawDumpPath); // Create a separate process and execute RAWdump.exe final String cmdLine[] = new String[] {rawDumpPath.getPath(), sourceFile.getPath()}; dumperProcess = Runtime.getRuntime().exec(cmdLine); // Get the stdout of RAWdump process as InputStream InputStream dumpStream = dumperProcess.getInputStream(); // Create the new RawDataFile String fileName = sourceFile.getName(); newRawFile = MSDKObjectBuilder.getRawDataFile(fileName, sourceFile, fileType, dataStore); // Read the dump data parser = new RawDumpParser(newRawFile, dataStore); parser.readRAWDump(dumpStream); // Cleanup dumpStream.close(); dumperProcess.destroy(); try { FileUtils.deleteDirectory(tempFolder); } catch (IOException e) { // Ignore errors while deleting the tmp folder } if (canceled) return null; } catch (Throwable e) { if (dumperProcess != null) dumperProcess.destroy(); throw new MSDKException(e); } logger.info("Finished parsing " + sourceFile); return newRawFile; }
/** {@inheritDoc} */ @Override public Float getFinishedPercentage() { if (parser == null) return 0f; else return parser.getFinishedPercentage(); }