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

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

Introduction

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

Prototype

FileContent getContent() throws FileSystemException;

Source Link

Document

Returns this file's content.

Usage

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

/**
 * Runs SWAN calculation. The following steps are processed:
 * <ul>/*  w w w. ja  v a 2  s.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.SwanResultProcessor.java

private void processSWANTabFile(final FileObject swanResOutTabFile, final FileObject swanResShiftFile) {
    final GM_Position lShiftPosition = SWANDataConverterHelper.readCoordinateShiftValues(swanResShiftFile);
    if (lShiftPosition == null)
        return;//from   w ww  .j a  v  a 2s.c  o m

    try {
        // FIXME: why?! should never happen...!
        if (swanResOutTabFile.isContentOpen())
            swanResOutTabFile.close();

        final FileObject swanResOutTabFileBackUp = swanResOutTabFile.getParent()
                .resolveFile(swanResOutTabFile.getName().getBaseName() + ".bck"); //$NON-NLS-1$
        swanResOutTabFile.moveTo(swanResOutTabFileBackUp);

        final OutputStream lOutStream = swanResOutTabFile.getContent().getOutputStream();
        final Formatter lFormatter = new Formatter(lOutStream, Charset.defaultCharset().name(), Locale.US);

        final BufferedReader lInDataStream = new BufferedReader(
                new InputStreamReader(swanResOutTabFileBackUp.getContent().getInputStream()));

        while (lInDataStream.ready()) {
            final String lStrTmpLine = lInDataStream.readLine().trim();
            if (lStrTmpLine.startsWith("%")) //$NON-NLS-1$
            {
                lFormatter.format("%s\n", lStrTmpLine); //$NON-NLS-1$
                continue;
            }

            final StringTokenizer lStrTokenizer = new StringTokenizer(lStrTmpLine, " "); //$NON-NLS-1$
            int lIntTokenCounter = 0;
            String lStrNewLine = ""; //$NON-NLS-1$
            while (lStrTokenizer.hasMoreTokens()) {
                final String lStrToken = lStrTokenizer.nextToken();
                if (lIntTokenCounter == 1) {
                    lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$
                            NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getX());
                } else if (lIntTokenCounter == 2) {
                    lStrNewLine += String.format(Locale.US, "%.5f\t", //$NON-NLS-1$
                            NumberUtils.parseQuietDouble(lStrToken) + lShiftPosition.getY());
                } else {
                    lStrNewLine += lStrToken + "\t"; //$NON-NLS-1$
                }
                lIntTokenCounter++;
            }
            lFormatter.format("%s\n", lStrNewLine); //$NON-NLS-1$
        }

        // FIXME: not closed in a save way!
        lFormatter.close();
        lInDataStream.close();
        lOutStream.close();
    } catch (final Exception e) {
        // FIXME: this is no way to handle an error !
    }
}

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

/**
 * Runs SWAN calculation. The following steps are processed:
 * <ul>/* ww  w . j a  v a 2s .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_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();
    }
}

From source file:org.kalypso.service.unittests.VFSAcceptCertificate.java

/**
 * This function will try to read a file via https to the local tmp-directory.
 *///from   w w w. j  ava  2  s  . c o  m
@Test
public void testVFSAcceptCertificate() throws IOException {
    /* Configure proxy for testing. */
    System.setProperty("http.proxySet", "true");
    System.setProperty("http.proxyHost", "proxy.bce01.de");
    System.setProperty("http.proxyPort", "8080");

    /* All certificates should be accepted! */
    System.setProperty("javax.net.ssl.keyStoreType", "JKS");
    System.setProperty("javax.net.ssl.keyStore",
            "C:/Albert/Temp/Projekte/InformDSS/Zertifikate/Client/keystore.jks");
    System.setProperty("javax.net.ssl.keyStorePassword", "key4ssl");
    System.setProperty("javax.net.ssl.trustStoreType", "JKS");
    System.setProperty("javax.net.ssl.trustStore",
            "C:/Albert/Temp/Projekte/InformDSS/Zertifikate/Server/truststore.jks");
    System.setProperty("javax.net.ssl.trustStorePassword", "key4ssl");

    final FileObject remoteFile = VFSUtilities.checkProxyFor(
            "https://WebDAV:webdav@informdss.bafg.de/webdav/results/CalcJob-0-1210650775870/simulation.log");

    KalypsoServiceWPSDebug.DEBUG.printf("Sending request ...\n");

    final File file = new File(FileUtilities.TMP_DIR, "vfs_test.tmp");
    final FileObject localFile = VFSUtilities.getManager().toFileObject(file);
    Assert.assertNotNull(localFile);

    VFSUtilities.copyFileTo(remoteFile, localFile);

    final InputStream inputStream = localFile.getContent().getInputStream();

    Assert.assertNotNull(inputStream);

    final String content = IOUtils.toString(inputStream);

    KalypsoServiceWPSDebug.DEBUG.printf("Content:\n");
    KalypsoServiceWPSDebug.DEBUG.printf(content + "\n");
}

From source file:org.kalypso.service.unittests.WebDavRead.java

/**
 * This function tries to copy a file from a webdav.
 *///from  www .j a  va2 s  .  com
@Test
public void testWebDavRead() throws IOException {
    final DefaultFileSystemManager manager = new DefaultFileSystemManager();
    manager.addProvider("webdav", new WebdavFileProvider());
    manager.addProvider("file", new DefaultLocalFileProvider());
    manager.init();

    final FileObject davFile = manager
            .resolveFile("webdav://albert:gnimfe@ibpm.bjoernsen.de/dav/pub/Test/test.txt");
    Assert.assertNotNull(davFile);

    final File file = new File(FileUtilities.TMP_DIR, "davRead.txt");
    final FileObject tmpFile = manager.toFileObject(file);
    Assert.assertNotNull(tmpFile);

    InputStream is = null;
    OutputStream os = null;

    try {
        is = davFile.getContent().getInputStream();
        os = tmpFile.getContent().getOutputStream();

        /* Copying ... */
        IOUtils.copy(is, os);

        is.close();
        os.close();
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }

    Assert.assertTrue(tmpFile.exists());
}

From source file:org.kalypso.service.wps.client.NonBlockingWPSRequest.java

@SuppressWarnings("unchecked")
public ExecuteResponseType getExecuteResponse(final FileSystemManager manager)
        throws Exception, InterruptedException {
    final FileObject statusFile = VFSUtilities.checkProxyFor(m_statusLocation, manager);
    if (statusFile.exists()) {
        /* Some variables for handling the errors. */
        boolean success = false;
        int cnt = 0;

        /* Try to read the status at least 3 times, before exiting. */
        JAXBElement<ExecuteResponseType> executeState = null;
        while (success == false) {
            final FileContent content = statusFile.getContent();
            InputStream inputStream = null;
            try {
                inputStream = content.getInputStream();
                final String xml = IOUtils.toString(inputStream);
                if (xml != null && !"".equals(xml)) //$NON-NLS-1$
                {//w w  w .j av a2  s  . c  o  m
                    final Object object = MarshallUtilities.unmarshall(xml);
                    executeState = (JAXBElement<ExecuteResponseType>) object;
                    success = true;
                }
            } catch (final Exception e) {
                /* An error has occured while copying the file. */
                KalypsoServiceWPSDebug.DEBUG
                        .printf("An error has occured with the message: " + e.getLocalizedMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$

                /* If a certain amount (here 2) of retries was reached before, rethrow the error. */
                if (cnt >= 2) {
                    KalypsoServiceWPSDebug.DEBUG
                            .printf("The second retry has failed, rethrowing the error ...\n"); //$NON-NLS-1$
                    throw e;
                }

                /* Retry the copying of the file. */
                cnt++;
                KalypsoServiceWPSDebug.DEBUG.printf("Retry: " + String.valueOf(cnt) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
                success = false;

                /* Wait for some milliseconds. */
                Thread.sleep(1000);
            } finally {
                IOUtils.closeQuietly(inputStream);
                statusFile.close();
            }
        }
        return executeState.getValue();
    } else
        return null;
}

From source file:org.kalypso.service.wps.server.operations.ExecuteOperation.java

/**
 * @see org.kalypso.service.wps.operations.IOperation#executeOperation(org.kalypso.service.ogc.RequestBean)
 *///from   ww w  .  ja va 2  s . c om
@Override
public StringBuffer executeOperation(final RequestBean request) throws OWSException {
    final StringBuffer response = new StringBuffer();

    /* Start the operation. */
    KalypsoServiceWPSDebug.DEBUG.printf("Operation \"Execute\" started.\n"); //$NON-NLS-1$

    /* Gets the identifier, but also unmarshalls the request, so it has to be done! */
    final String requestXml = request.getBody();
    Object executeRequest = null;
    try {
        executeRequest = MarshallUtilities.unmarshall(requestXml);
    } catch (final JAXBException e) {
        throw new OWSException(OWSException.ExceptionCode.NO_APPLICABLE_CODE, e, ""); //$NON-NLS-1$
    }

    /* Execute the simulation via a manager, so that more than one simulation can be run at the same time. */
    final WPSSimulationManager manager = WPSSimulationManager.getInstance();

    // TODO version 1.0
    final ExecuteMediator executeMediator = new ExecuteMediator(executeRequest);
    final WPSSimulationInfo info = manager.startSimulation(executeMediator);

    /* Prepare the execute response. */
    FileObject resultFile = null;
    InputStream inputStream = null;
    try {
        final FileObject resultDir = manager.getResultDir(info.getId());
        resultFile = resultDir.resolveFile("executeResponse.xml"); //$NON-NLS-1$
        int time = 0;
        final int timeout = 10000;
        final int delay = 500;
        while (!resultFile.exists() && time < timeout) {
            Thread.sleep(delay);
            time += delay;
        }
        final FileContent content = resultFile.getContent();
        inputStream = content.getInputStream();
        final String responseXml = IOUtils.toString(inputStream);
        response.append(responseXml);
    } catch (final Exception e) {
        throw new OWSException(OWSException.ExceptionCode.NO_APPLICABLE_CODE, e, ""); //$NON-NLS-1$
    } finally {
        /* Close the file object. */
        VFSUtilities.closeQuietly(resultFile);

        /* Close the input stream. */
        IOUtils.closeQuietly(inputStream);
    }

    return response;
}

From source file:org.kalypso.service.wps.utils.WPSUtilities.java

public static ExecuteResponseType readExecutionResponse(final FileSystemManager manager,
        final String statusLocation) throws CoreException {
    try {//from w w w .j a  v a 2  s.  c o m
        final FileObject statusFile = VFSUtilities.checkProxyFor(statusLocation, manager);
        if (!statusFile.exists())
            return null;

        /* Try to read the status at least 3 times, before exiting. */
        Exception lastError = new Exception();

        // TODO: timeout defined as approximately 3 seconds is in some how not always usable, set to 100.
        // Better to set it from predefined properties.

        // Hi Ilya, I think you missunderstood the number here.
        // It does not represent a timeout, but the number of times to try.
        // The Thread.sleep( 1000 ) in case of an error is only the time to wait,
        // before it is retried to read the execution response.
        // I changed the value back to 3. Holger
        for (int i = 0; i < 3; i++) {
            InputStream inputStream = null;
            try {
                final FileContent content = statusFile.getContent();
                inputStream = content.getInputStream();
                final String xml = IOUtils.toString(inputStream);
                if (xml == null || "".equals(xml)) //$NON-NLS-1$
                    throw new IOException(Messages.getString("org.kalypso.service.wps.utils.WPSUtilities.4") //$NON-NLS-1$
                            + statusFile.toString());

                final Object object = MarshallUtilities.unmarshall(xml);
                final JAXBElement<?> executeState = (JAXBElement<?>) object;
                return (ExecuteResponseType) executeState.getValue();
            } catch (final Exception e) {
                lastError = e;

                KalypsoServiceWPSDebug.DEBUG
                        .printf("An error has occured with the message: " + e.getLocalizedMessage() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
                KalypsoServiceWPSDebug.DEBUG.printf("Retry: " + String.valueOf(i) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$

                Thread.sleep(1000);
            } finally {
                IOUtils.closeQuietly(inputStream);
                statusFile.close();
            }
        }

        KalypsoServiceWPSDebug.DEBUG.printf("The second retry has failed, rethrowing the error ..."); //$NON-NLS-1$ //$NON-NLS-2$
        final IStatus status = StatusUtilities.createStatus(IStatus.ERROR,
                Messages.getString("org.kalypso.service.wps.utils.WPSUtilities.5") //$NON-NLS-1$
                        + lastError.getLocalizedMessage(),
                lastError);
        throw new CoreException(status);
    } catch (final Exception e) {
        e.printStackTrace();

        final IStatus status = StatusUtilities.createStatus(IStatus.ERROR,
                Messages.getString("org.kalypso.service.wps.utils.WPSUtilities.6") + e.getLocalizedMessage(), //$NON-NLS-1$
                e);
        throw new CoreException(status);
    }
}

From source file:org.luwrain.app.commander.InfoAndProperties.java

static public long getTotalSize(FileObject fileObj) throws org.apache.commons.vfs2.FileSystemException {
    NullCheck.notNull(fileObj, "fileObj");
    if (!fileObj.isFolder() && !fileObj.isFile())
        return 0;
    if (fileObj instanceof org.apache.commons.vfs2.provider.local.LocalFile
            && java.nio.file.Files.isSymbolicLink(java.nio.file.Paths.get(fileObj.getName().getPath())))
        return 0;
    if (!fileObj.isFolder())
        return fileObj.getContent().getSize();
    long res = 0;
    for (FileObject child : fileObj.getChildren())
        res += getTotalSize(child);//from   www. j a  va  2s .  c o m
    return res;
}

From source file:org.mycore.backend.filesystem.MCRCStoreVFS.java

@Override
protected String doStoreContent(MCRFileReader file, MCRContentInputStream source) throws Exception {
    StringBuilder storageId = new StringBuilder();

    String[] slots = buildSlotPath();
    // Recursively create directory name
    for (String slot : slots) {
        storageId.append(slot).append("/");
    }//from   ww w .  j av a2  s.  co  m

    String fileId = buildNextID(file);
    storageId.append(fileId);

    FileObject targetObject = fsManager.resolveFile(getBase(), storageId.toString());
    FileContent targetContent = targetObject.getContent();
    try (OutputStream out = targetContent.getOutputStream()) {
        IOUtils.copy(source, out);
    } finally {
        targetContent.close();
    }
    return storageId.toString();
}