Example usage for org.apache.commons.vfs2 FileUtil getContent

List of usage examples for org.apache.commons.vfs2 FileUtil getContent

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileUtil getContent.

Prototype

public static byte[] getContent(final FileObject file) throws IOException 

Source Link

Document

Returns the content of a file, as a byte array.

Usage

From source file:com.stratuscom.harvester.classloading.VirtualFileSystemClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    try {//  w w w  . j  a  v a  2 s  . c o  m
        return (Class) Security.doPrivileged(new PrivilegedExceptionAction<Class>() {

            public Class run() throws ClassNotFoundException {
                String resourceName = classToResourceName(name);
                FileObject resourceFileObject = findResourceFileObject(resourceName);
                if (resourceFileObject == null) {
                    if (log.isLoggable(Level.FINE)) {
                        log.fine(getDebugName() + " was asked for " + resourceName + " but couldn't find it.");
                    }
                    throw new ClassNotFoundException(name + "(" + resourceName + ")");
                }
                try {
                    byte[] bytes = FileUtil.getContent(resourceFileObject);
                    return defineClass(name, bytes, 0, bytes.length);
                } catch (IOException ioe) {
                    if (log.isLoggable(Level.FINE)) {
                        log.fine(getDebugName() + " was asked for " + resourceName
                                + " but got IOException while loading it.");
                    }
                    throw new ClassNotFoundException(name, ioe);
                }

            }
        });
    } catch (PrivilegedActionException ex) {
        throw (ClassNotFoundException) ex.getException();
    }
}

From source file:org.apache.river.container.classloading.VirtualFileSystemClassLoader.java

@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
    try {/*w  w  w . j a va 2  s  .  co  m*/
        return (Class) Security.doPrivileged(new PrivilegedExceptionAction<Class>() {

            public Class run() throws ClassNotFoundException {
                String resourceName = classToResourceName(name);
                FileObject resourceFileObject = findResourceFileObject(resourceName);
                if (resourceFileObject == null) {
                    throw new ClassNotFoundException(name + "(" + resourceName + ")");
                }
                try {
                    byte[] bytes = FileUtil.getContent(resourceFileObject);
                    return defineClass(name, bytes, 0, bytes.length);
                } catch (IOException ioe) {
                    throw new ClassNotFoundException(name, ioe);
                }

            }
        });
    } catch (PrivilegedActionException ex) {
        throw (ClassNotFoundException) ex.getException();
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.IterationInfo.java

@Override
public void readIterFile() throws IOException {
    m_itrFile.refresh();/*from  w  w w.j a v  a 2 s. c  o  m*/
    if (!m_itrFile.exists())
        return;

    /* Read file and write outputs */
    LineNumberReader lnr = null;
    try {
        // final InputStream inputStream = m_itrFile.getContent().getInputStream();
        final byte[] content = FileUtil.getContent(m_itrFile);
        // lnr = new LineNumberReader( new BufferedReader( new InputStreamReader( inputStream ) ) );
        lnr = new LineNumberReader(new StringReader(new String(content, Charset.defaultCharset())));
        while (lnr.ready()) {
            final String line = lnr.readLine();
            if (line == null)
                break;

            processLine(line, lnr.getLineNumber());
        }
    } catch (final FileNotFoundException e) {
        // FIXME: stati are never used; what happened here?!
        //      if( lnr == null )
        //        StatusUtilities.createStatus( IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S, Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.IterationInfo.1" ), e ); //$NON-NLS-1$
        //
        //      final String msg = Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.IterationInfo.2", lnr.getLineNumber() ); //$NON-NLS-1$
        //      StatusUtilities.createStatus( IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S, msg, e );
    } finally {
        IOUtils.closeQuietly(lnr);
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.IterationInfoSWAN.java

@Override
public void readIterFile() throws IOException {
    m_itrFile.refresh();/*from w ww  .  j  a  v a2s .c om*/
    if (!m_itrFile.exists())
        return;

    /* Read file and write outputs */
    LineNumberReader lnr = null;
    try {
        final byte[] content = FileUtil.getContent(m_itrFile);
        lnr = new LineNumberReader(new StringReader(new String(content, Charset.defaultCharset())));
        while (lnr.ready()) {
            final String line = lnr.readLine();
            if (line == null)
                break;
            processLine(line, lnr.getLineNumber());
        }
    } catch (final FileNotFoundException e) {
        // FIXME: these stati are never used; what happened here?
        //      if( lnr == null )
        //        StatusUtilities.createStatus( IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S, Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.IterationInfo.1" ), e ); //$NON-NLS-1$
        //
        //      final String msg = Messages.getString( "org.kalypso.kalypsomodel1d2d.sim.IterationInfo.2", lnr.getLineNumber() ); //$NON-NLS-1$
        //      StatusUtilities.createStatus( IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S, msg, e );
    } finally {
        IOUtils.closeQuietly(lnr);
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.IterationInfoTelemac.java

@Override
public void readIterFile() throws IOException {
    m_itrFile.refresh();/*from   www.  ja v  a2  s  .  c o m*/
    if (!m_itrFile.exists())
        return;

    /* Read file and write outputs */
    LineNumberReader lnr = null;
    try {
        final byte[] content = FileUtil.getContent(m_itrFile);
        lnr = new LineNumberReader(new StringReader(new String(content, Charset.defaultCharset())));
        while (lnr.ready()) {
            final String line = lnr.readLine();
            if (line == null)
                break;
            processLine(line, lnr.getLineNumber());
        }
    } catch (final FileNotFoundException e) {
        if (lnr == null)
            StatusUtilities.createStatus(IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S,
                    Messages.getString("org.kalypso.kalypsomodel1d2d.sim.IterationInfo.1"), e); //$NON-NLS-1$

        final String msg = Messages.getString("org.kalypso.kalypsomodel1d2d.sim.IterationInfo.2", //$NON-NLS-1$
                lnr.getLineNumber());
        StatusUtilities.createStatus(IStatus.WARNING, ISimulation1D2DConstants.CODE_RMA10S, msg, e);
    } finally {
        IOUtils.closeQuietly(lnr);
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.java

/**
 * Runs < rma10s calculation. The following steps are processed:
 * <ul>/*from www  .  j a v  a 2s. c o m*/
 * <li>write rma10s ASCII files to temporary directory according to provided gml-models</li>
 * <li>write .exe to temporary directory</li>
 * <li>execute the .exe</li>
 * </ul>
 * 
 * @see org.kalypso.simulation.core.ISimulation#run(java.io.File, org.kalypso.simulation.core.ISimulationDataProvider, org.kalypso.simulation.core.ISimulationResultEater,
 *      org.kalypso.simulation.core.ISimulationMonitor)
 */
@Override
public void run(final File tmpdir, final ISimulationDataProvider inputProvider,
        final ISimulationResultEater resultEater, final ISimulationMonitor monitor) throws SimulationException {
    final SimulationMonitorAdaptor progressMonitor = new SimulationMonitorAdaptor(monitor);
    final ICancelable progressCancelable = new ProgressCancelable(progressMonitor);

    try {
        m_log = new GeoLog(KalypsoModel1D2DPlugin.getDefault().getLog());
    } catch (final Exception e) {
        throw new SimulationException("Could not initialize GeoLog", e); //$NON-NLS-1$
    }

    OutputStream logOS = null;
    OutputStream errorOS = null;
    FileSystemManagerWrapper manager = null;
    try {
        // TODO: use URI instead of URL
        final String version = (String) inputProvider.getInputForID(INPUT_RMA_VERSION);
        final URL modelFileUrl = (URL) inputProvider.getInputForID(INPUT_MESH);
        final URL controlFileUrl = (URL) inputProvider.getInputForID(INPUT_CONTROL);
        final URL buildingFileUrl = (URL) inputProvider.getInputForID(INPUT_BUILDINGS);
        final URL bcwqFileUrl = (URL) inputProvider.getInputForID(INPUT_BC_WQ);
        final URL windFileUrl = (URL) inputProvider.getInputForID(INPUT_WIND);
        final URL windCoordFileUrl = (URL) inputProvider.getInputForID(INPUT_WIND_COORD);

        manager = VFSUtilities.getNewManager();
        final FileObject modelFile = manager.resolveFile(modelFileUrl.toString());
        final FileObject controlFile = manager.resolveFile(controlFileUrl.toString());
        final FileObject buildingFile = manager.resolveFile(buildingFileUrl.toString());
        final FileObject bcwqFile = manager.resolveFile(bcwqFileUrl.toString());
        final FileObject windFile = manager.resolveFile(windFileUrl.toString());
        final FileObject windCoordFile = manager.resolveFile(windCoordFileUrl.toString());

        // find executable for version
        final File exeFile = findRma10skExe(version);
        final FileObject executableFile = manager.toFileObject(exeFile);
        final String executableName = exeFile.getName();

        // Generate the process-factory-id
        // TODO: at the moment, this is hard wired.... later we should get it from System.properties and/or from our own
        // simulation-id (as we are no simulation, this does not work yet).
        // Example1: org.kalypso.simulation.process.factory.<simulation-id>=<factory-id>
        // For the moment, we could also provide it directly from outside or from a system-property
        // (fall-back should always be the default factory)

        final String processFactoryId = IProcessFactory.DEFAULT_PROCESS_FACTORY_ID;
        // simply switch here and we run in the grid :)
        //      final String processFactoryId = "org.kalypso.simulation.gridprocess"; //$NON-NLS-1$

        final String tempDirName;
        if (inputProvider.hasID(INPUT_WORKING_DIR))
            tempDirName = (String) inputProvider.getInputForID(INPUT_WORKING_DIR);
        else
            tempDirName = tmpdir.getName();

        final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName,
                executableName);

        // add sandbox dir to results for monitoring (empty at this time)
        final String sandboxDirectory = process.getSandboxDirectory();

        try {
            final URI resultURI = new URI(sandboxDirectory);
            if (resultURI.getScheme().equals("file")) //$NON-NLS-1$
                resultEater.addResult(OUTPUT_RESULTS, new File(resultURI));
            else
                resultEater.addResult(OUTPUT_RESULTS, resultURI);
        } catch (final URISyntaxException e) {
            e.printStackTrace();
        }

        // check if user cancelled
        if (progressMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }

        // copy executable and write input files
        // final FileObject
        workingDir = manager.resolveFile(sandboxDirectory);
        VFSUtilities.copyFileTo(executableFile, workingDir);
        VFSUtilities.copyFileTo(modelFile, workingDir);
        VFSUtilities.copyFileTo(controlFile, workingDir);
        VFSUtilities.copyFileTo(buildingFile, workingDir);
        VFSUtilities.copyFileTo(bcwqFile, workingDir);
        VFSUtilities.copyFileTo(windFile, workingDir);
        VFSUtilities.copyFileTo(windCoordFile, workingDir);

        final File stdoutFile = new File(tmpdir, "exe.log"); //$NON-NLS-1$
        final File stderrFile = new File(tmpdir, "exe.err"); //$NON-NLS-1$

        logOS = new BufferedOutputStream(new FileOutputStream(stdoutFile));
        errorOS = new BufferedOutputStream(new FileOutputStream(stderrFile));

        // check if user cancelled
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        System.gc();
        // Run the Calculation
        m_log.formatLog(IStatus.INFO, ISimulation1D2DConstants.CODE_RUNNING,
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMA10Calculation.0") + ": " //$NON-NLS-1$//$NON-NLS-2$
                        + executableName);
        process.startProcess(logOS, errorOS, null, progressCancelable);

        // decide based on ERROR.OUT if simulation was successful
        final FileObject errorFile = workingDir.resolveFile("ERROR.OUT"); //$NON-NLS-1$
        if (errorFile == null || !errorFile.exists() || errorFile.getContent().getSize() == 0) {
            /* Successfully finished simulation */
            progressMonitor.done(new Status(IStatus.OK, KalypsoModel1D2DPlugin.PLUGIN_ID,
                    Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMA10Calculation.20"))); //$NON-NLS-1$
        } else {
            /* ERROR: return contents of error file as error message */
            final byte[] content = FileUtil.getContent(errorFile);
            final String charset = Charset.defaultCharset().name();
            final String errorMessage = new String(content, charset);
            final IStatus status = new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, errorMessage);
            progressMonitor.done(status);
            throw new CoreException(status);
        }
    } catch (final ProcessTimeoutException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.0"), e); //$NON-NLS-1$
    } catch (final OperationCanceledException e) {
        // do not throw an exception if cancelled
        monitor.setFinishInfo(IStatus.CANCEL,
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"));//$NON-NLS-1$
        monitor.setMessage(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"));//$NON-NLS-1$
        return;
    } catch (final CoreException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.2"), e); //$NON-NLS-1$
    } catch (final IOException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.3"), e); //$NON-NLS-1$
    } finally {
        IOUtils.closeQuietly(logOS);
        IOUtils.closeQuietly(errorOS);

        if (manager != null)
            manager.close();
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.SWANKalypsoSimulation.java

/**
 * Runs SWAN calculation. The following steps are processed:
 * <ul>/*from   ww w  .  j  ava2s.c o m*/
 * <li>write swan.exe to temporary directory</li>
 * <li>execute the swan.exe</li>
 * <li>read results files and process them to the output directory</li>
 * </ul>
 *
 * @see org.kalypso.simulation.core.ISimulation#run(java.io.File, org.kalypso.simulation.core.ISimulationDataProvider,
 *      org.kalypso.simulation.core.ISimulationResultEater, org.kalypso.simulation.core.ISimulationMonitor)
 */
@Override
public void run(final File tmpdir, final ISimulationDataProvider inputProvider,
        final ISimulationResultEater resultEater, final ISimulationMonitor monitor) throws SimulationException {
    final SimulationMonitorAdaptor progressMonitor = new SimulationMonitorAdaptor(monitor);
    final ICancelable progressCancelable = new ProgressCancelable(progressMonitor);

    try {
        m_log = new GeoLog(KalypsoModel1D2DPlugin.getDefault().getLog());
    } catch (final Exception e) {
        throw new SimulationException("Could not initialize GeoLog", e); //$NON-NLS-1$
    }

    OutputStream logOS = null;
    OutputStream errorOS = null;
    FileSystemManagerWrapper manager = null;
    try {
        manager = VFSUtilities.getNewManager();

        // TODO: specific error message if exe was not found
        final String version = (String) inputProvider.getInputForID(INPUT_SWAN_VERSION);
        final File exeFile = findSWANExe(version);
        final FileObject executableFile = manager.toFileObject(exeFile);
        final String executableName = exeFile.getName();

        final String processFactoryId = IProcessFactory.DEFAULT_PROCESS_FACTORY_ID;
        // simply switch here and we run in the grid :)
        // Remark: it would be good also for swan :)
        //      final String processFactoryId = "org.kalypso.simulation.gridprocess"; //$NON-NLS-1$

        final String tempDirName = tmpdir.getName();
        final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName,
                executableName);
        // process.setProgressMonitor( progress );

        // add sandbox dir to results for monitoring (empty at this time)
        final String sandboxDirectory = process.getSandboxDirectory();
        try {
            resultEater.addResult(SWANKalypsoSimulation.OUTPUT_RESULTS, new URI(sandboxDirectory)); //$NON-NLS-1$
        } catch (final URISyntaxException e) {
            e.printStackTrace();
        }

        // copy executable and write input files
        final FileObject lFileObjWorkingDir = manager.resolveFile(sandboxDirectory);
        VFSUtilities.copyFileTo(executableFile, lFileObjWorkingDir);

        final String lStrPreSWANURL = (String) inputProvider.getInputForID(PreSWANKalypso.OUTPUT_PATH_SWAN);
        final FileObject lFileObjPreResultsDir = manager.resolveFile(lStrPreSWANURL);
        copyFilesToWorkDir(lFileObjPreResultsDir, lFileObjWorkingDir);

        final File stdoutFile = new File(tmpdir, "exe.log"); //$NON-NLS-1$
        final File stderrFile = new File(tmpdir, "exe.err"); //$NON-NLS-1$

        logOS = new BufferedOutputStream(new FileOutputStream(stdoutFile));
        errorOS = new BufferedOutputStream(new FileOutputStream(stderrFile));

        // Run the Calculation
        // final SubMonitor progress = SubMonitor.convert( progressMonitor, m_controlModel.getNCYC() );
        m_log.formatLog(IStatus.INFO, CODE_RUNNING,
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.0") + ": " //$NON-NLS-1$//$NON-NLS-2$
                        + executableName);
        progressMonitor.subTask(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.15")); //$NON-NLS-1$
        process.startProcess(logOS, errorOS, null, progressCancelable);

        // decide based on ERROR.OUT if simulation was successful
        final FileObject errorFile = lFileObjWorkingDir.resolveFile("ERROR.OUT"); //$NON-NLS-1$
        if (errorFile == null || !errorFile.exists() || errorFile.getContent().getSize() == 0) {
            /* Successfully finished simulation */
            progressMonitor.done(new Status(IStatus.OK, KalypsoModel1D2DPlugin.PLUGIN_ID,
                    Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.20"))); //$NON-NLS-1$
        } else {
            /* ERROR: return contents of error file as error message */
            final byte[] content = FileUtil.getContent(errorFile);
            final String charset = Charset.defaultCharset().name();
            final String errorMessage = new String(content, charset);
            final IStatus status = new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, errorMessage);
            progressMonitor.done(status);
        }
        // TODO: implement the results eater
    } catch (final ProcessTimeoutException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.0"), e); //$NON-NLS-1$
    } catch (final OperationCanceledException e) {
        final CoreException ce = new CoreException(new Status(IStatus.CANCEL, KalypsoModel1D2DPlugin.PLUGIN_ID,
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.2"), e)); //$NON-NLS-1$

        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"), ce); //$NON-NLS-1$
    } catch (final CoreException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.2"), e); //$NON-NLS-1$
    } catch (final IOException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.3"), e); //$NON-NLS-1$
    } finally {
        IOUtils.closeQuietly(logOS);
        IOUtils.closeQuietly(errorOS);

        if (manager != null)
            manager.close();
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.TelemacKalypsoSimulation.java

/**
 * Runs SWAN calculation. The following steps are processed:
 * <ul>/*from  w  w  w.ja va 2 s. co  m*/
 * <li>write swan.exe to temporary directory</li>
 * <li>execute the swan.exe</li>
 * <li>read results files and process them to the output directory</li>
 * </ul>
 * 
 * @see org.kalypso.simulation.core.ISimulation#run(java.io.File, org.kalypso.simulation.core.ISimulationDataProvider,
 *      org.kalypso.simulation.core.ISimulationResultEater, org.kalypso.simulation.core.ISimulationMonitor)
 */
@Override
public void run(final File tmpdir, final ISimulationDataProvider inputProvider,
        final ISimulationResultEater resultEater, final ISimulationMonitor monitor) throws SimulationException {
    final SimulationMonitorAdaptor progressMonitor = new SimulationMonitorAdaptor(monitor);
    final ICancelable progressCancelable = new ProgressCancelable(progressMonitor);

    try {
        m_log = new GeoLog(KalypsoModel1D2DPlugin.getDefault().getLog());
    } catch (final Exception e) {
        throw new SimulationException("Could not initialize GeoLog", e); //$NON-NLS-1$
    }

    OutputStream logOS = null;
    OutputStream errorOS = null;
    FileSystemManagerWrapper manager = null;
    try {
        manager = VFSUtilities.getNewManager();

        // TODO: specific error message if exe was not found
        final String version = (String) inputProvider.getInputForID(INPUT_TELEMAC_VERSION);
        final File exeFile = findTelemacBatch(version, tmpdir);
        final FileObject executableFile = manager.toFileObject(exeFile);
        final String executableName = exeFile.getName();

        final String processFactoryId = IProcessFactory.DEFAULT_PROCESS_FACTORY_ID;
        // simply switch here and we run in the grid :)
        // Remark: it would be good also for swan :)
        //      final String processFactoryId = "org.kalypso.simulation.gridprocess"; //$NON-NLS-1$

        final String tempDirName = tmpdir.getName();
        final IProcess process = KalypsoCommonsExtensions.createProcess(processFactoryId, tempDirName,
                executableName);
        // process.setProgressMonitor( progress );

        // add sandbox dir to results for monitoring (empty at this time)
        final String sandboxDirectory = process.getSandboxDirectory();
        try {
            resultEater.addResult(TelemacKalypsoSimulation.OUTPUT_RESULTS, new URI(sandboxDirectory)); //$NON-NLS-1$
        } catch (final URISyntaxException e) {
            e.printStackTrace();
        }

        // copy executable and write input files
        final FileObject lFileObjWorkingDir = manager.resolveFile(sandboxDirectory);
        VFSUtilities.copyFileTo(executableFile, lFileObjWorkingDir);

        final String lStrPreTelemacURL = (String) inputProvider
                .getInputForID(PreTelemacKalypso.OUTPUT_PATH_Telemac);
        final FileObject lFileObjPreResultsDir = manager.resolveFile(lStrPreTelemacURL);
        copyFilesToWorkDir(lFileObjPreResultsDir, lFileObjWorkingDir);

        final File stdoutFile = new File(tmpdir, "exe.log"); //$NON-NLS-1$
        final File stderrFile = new File(tmpdir, "exe.err"); //$NON-NLS-1$

        logOS = new BufferedOutputStream(new FileOutputStream(stdoutFile));
        errorOS = new BufferedOutputStream(new FileOutputStream(stderrFile));

        // Run the Calculation
        // final SubMonitor progress = SubMonitor.convert( progressMonitor, m_controlModel.getNCYC() );
        m_log.formatLog(IStatus.INFO, CODE_RUNNING,
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.0") + ": " //$NON-NLS-1$//$NON-NLS-2$
                        + executableName);
        progressMonitor.subTask(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.15")); //$NON-NLS-1$
        process.startProcess(logOS, errorOS, null, progressCancelable);

        // decide based on ERROR.OUT if simulation was successful
        final FileObject errorFile = lFileObjWorkingDir.resolveFile("ERROR.OUT"); //$NON-NLS-1$
        if (errorFile == null || !errorFile.exists() || errorFile.getContent().getSize() == 0) {
            /* Successfully finished simulation */
            progressMonitor.done(StatusUtilities
                    .createOkStatus(Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.20"))); //$NON-NLS-1$
        } else {
            /* ERROR: return contents of error file as error message */
            final byte[] content = FileUtil.getContent(errorFile);
            final String charset = Charset.defaultCharset().name();
            final String errorMessage = new String(content, charset);
            final IStatus status = StatusUtilities.createErrorStatus(errorMessage);
            progressMonitor.done(status);
        }
        // TODO: implement the results eater
    } catch (final ProcessTimeoutException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.0"), e); //$NON-NLS-1$
    } catch (final OperationCanceledException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.1"), //$NON-NLS-1$
                new CoreException(StatusUtilities.createStatus(IStatus.CANCEL,
                        Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.2"), e))); //$NON-NLS-1$
    } catch (final CoreException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.2"), e); //$NON-NLS-1$
    } catch (final IOException e) {
        throw new SimulationException(
                Messages.getString("org.kalypso.kalypsomodel1d2d.sim.RMAKalypsoSimulation.3"), e); //$NON-NLS-1$
    } finally {
        IOUtils.closeQuietly(logOS);
        IOUtils.closeQuietly(errorOS);

        if (manager != null)
            manager.close();
    }
}