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

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

Introduction

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

Prototype

FileName getName();

Source Link

Document

Returns the name of this file.

Usage

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

private FileObject[] find2dFiles(final FileObject remoteWorking) throws IOException {
    final List<FileObject> resultList = new ArrayList<>();
    if (remoteWorking == null)
        return null;

    final FileObject[] children = remoteWorking.getChildren();
    for (final FileObject child : children) {
        final FileName childName = child.getName();
        final String baseName = childName.getBaseName();
        if (FilenameUtils.wildcardMatch(baseName, "*.2d") || FilenameUtils.wildcardMatch(baseName, "*.2d.zip")) //$NON-NLS-1$ //$NON-NLS-2$
        {/*from w  ww  .j  a v a2  s  .  com*/
            resultList.add(child);
        }

    }
    return resultList.toArray(new FileObject[resultList.size()]);
}

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

private FileObject findTelemacResultFile(final FileObject resultDir) {
    if (resultDir == null)
        return null;

    FileObject[] children = null;
    try {//w  w  w .  j  a  v  a  2s.  c  o m
        children = resultDir.getChildren();
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
    for (final FileObject child : children) {
        final FileName childName = child.getName();
        final String baseName = childName.getBaseName();
        if (FilenameUtils.wildcardMatch(baseName, "*res*.slf*")) //$NON-NLS-1$ 
        {
            return child;
        }
    }

    final IPath path = ResultMeta1d2dHelper.getSavedPathFromResultData(m_calcUnitMeta,
            ResultMeta1d2dHelper.TELEMAC_RAW_DATA_META_NAME);
    if (path != null) {
        try {
            return resultDir.getParent().resolveFile(path.toOSString());
        } catch (final Exception e) {
            m_geoLog.formatLog(IStatus.INFO, CODE_RUNNING_FINE,
                    Messages.getString("org.kalypso.kalypsomodel1d2d.sim.ResultManager.15"), //$NON-NLS-1$
                    resultDir.getName().getBaseName());
            return null;
        }
    }
    return null;
}

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

private Date getStepMapDate(final FileObject file) {
    final String baseName = file.getName().getBaseName();
    if (baseName.equals("steady.2d")) //$NON-NLS-1$
        return STEADY_DATE;

    if (baseName.equals("maxi.2d")) //$NON-NLS-1$
        return MAXI_DATE;

    if (baseName.equals("steady.2d") || baseName.equals("maxi.2d") || baseName.equals("mini.2d") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            || baseName.equals("model.2d")) //$NON-NLS-1$
        return null;

    if (baseName.endsWith(".2d.zip")) //$NON-NLS-1$
        return ResultMeta1d2dHelper.resolveDateFromResultStep(file);

    final String resultFileName = baseName;
    final int index = resultFileName.indexOf("."); //$NON-NLS-1$
    final CharSequence sequence = resultFileName.subSequence(1, index);
    final String string = sequence.toString();
    final int step = Integer.parseInt(string);

    return getDateOfTimeStepNr(step);

}

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

private void copyFilesToWorkDir(final FileObject tmpDir, final FileObject targetDir)
        throws FileSystemException, IOException {
    final List<FileObject> lListFilesToRemove = new ArrayList<>();
    final Set<String> exclusionFileNamesToMove = new HashSet<>();
    exclusionFileNamesToMove.add(EXECUTE_RESPONSE_XML);
    // copy input files
    for (int i = 0; i < tmpDir.getChildren().length; i++) {
        final FileObject actFile = tmpDir.getChildren()[i];
        if (!exclusionFileNamesToMove.contains(actFile.getName().getBaseName().toLowerCase().trim())) {
            VFSUtilities.copyFileTo(actFile, targetDir);
            lListFilesToRemove.add(actFile);
        }//from  w  ww  . j a  v a 2  s.  c  o m
    }
    for (final FileObject actFile : lListFilesToRemove) {
        actFile.delete();
    }

}

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;/*w w w  .j a v  a 2  s .  co 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

private void copyFilesToWorkDir(final FileObject tmpDir, final FileObject targetDir)
        throws FileSystemException, IOException {
    List<FileObject> lListFilesToRemove = new ArrayList<FileObject>();
    Set<String> exclusionFileNamesToMove = new HashSet<String>();
    exclusionFileNamesToMove.add(EXECUTE_RESPONSE_XML);
    // copy input files
    for (int i = 0; i < tmpDir.getChildren().length; i++) {
        FileObject actFile = tmpDir.getChildren()[i];
        if (!exclusionFileNamesToMove.contains(actFile.getName().getBaseName().toLowerCase().trim())) {
            VFSUtilities.copyFileTo(actFile, targetDir);
            lListFilesToRemove.add(actFile);
        }//from ww w  .  j  a  va  2  s .  c om
    }
    for (Iterator<FileObject> iterator = lListFilesToRemove.iterator(); iterator.hasNext();) {
        FileObject actFile = iterator.next();
        actFile.delete();
    }

}

From source file:org.kalypso.service.wps.utils.simulation.WPSSimulationResultEater.java

private void copyResult(final File sourceFile, final FileObject destination) throws IOException {
    /* Converting the source file to a file object from VFS. */
    final FileObject source = m_vfsManager.toFileObject(sourceFile);
    if (FileType.FOLDER.equals(source.getType())) {
        /* Directory copy. */
        KalypsoServiceWPSDebug.DEBUG//from  w  w w .  j av  a2  s  . c  o  m
                .printf("Copy directory " + source.getName() + " to " + destination.getName() + " ...\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        VFSUtilities.copyDirectoryToDirectory(source, destination);
    } else if (FileType.FILE.equals(source.getType())) {
        /* File copy. */
        KalypsoServiceWPSDebug.DEBUG
                .printf("Copy file " + source.getName() + " to " + destination.getName() + " ...\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        VFSUtilities.copyFileTo(source, destination);
    }
}

From source file:org.kalypso.ui.wizards.results.Import2DResultsOperation.java

private void importFile(final FileObject inputFile, final File outputDir, final ICalcUnitResultMeta calcMeta,
        final IProgressMonitor monitor) throws InvocationTargetException {
    final Date stepDate = findStepDate(inputFile);

    final File resultDir = new File(outputDir, inputFile.getName().getBaseName());
    resultDir.mkdirs();/*ww  w.ja v a2s  .  c  o m*/

    final IFlowRelationshipModel flowModel = null;
    final IControlModel1D2D controlModel = null;
    final IFEDiscretisationModel1d2d discModel = null;

    final List<ResultType> parameter = null; // read all default parameters

    final ProcessResult2DOperation operation = new ProcessResult2DOperation(inputFile, null, resultDir,
            flowModel, controlModel, discModel, parameter, stepDate, calcMeta, true, null);
    final IStatus fileStatus = operation.execute(monitor);
    m_stati.add(fileStatus);
}

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);/*  w w  w .j  av a2 s .  c  om*/
    return res;
}

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

boolean runHookOnSelected(String hookPrefix) {
    NullCheck.notEmpty(hookPrefix, "hookPrefix");
    final FileObject obj = getSelectedEntry();
    if (obj == null)
        return false;
    if (isLocalDir()) {
        if (!(obj instanceof org.apache.commons.vfs2.provider.local.LocalFile))
            throw new RuntimeException("The entry is not a local file while the local dir is opened");
        final File f = new File(obj.getName().getPath());
        try {//from   w w  w  .  j av  a 2  s.c  om
            if (luwrain.xRunHooks(hookPrefix + ".local.custom", new Object[] { f },
                    Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY))
                return true;
            return luwrain.xRunHooks(hookPrefix + ".local.default", new Object[] { f },
                    Luwrain.HookStrategy.CHAIN_OF_RESPONSIBILITY);
        } catch (RuntimeException e) {
            luwrain.message(luwrain.i18n().getExceptionDescr(e), Luwrain.MessageType.ERROR);
            return true;
        }
    }
    //FIXME:remote 
    return false;
}