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:com.github.songsheng.vfs2.provider.nfs.NfsFileObject.java

@Override
protected void doRename(final FileObject newfile) throws Exception {
    file.renameTo(createNfsFile(newfile.getName()));
}

From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java

private File buildNode(final File parent, final FileObject file)
        throws org.apache.commons.vfs2.FileSystemException {
    String name = file.getName().getBaseName();

    File n = new AbstractFile(this, name, parent, file.getType() == FileType.FOLDER, true);
    if (file.getType() == FileType.FILE) {
        FileContent content = file.getContent();
        n.setLastModified(content.getLastModifiedTime());
        n.setSize(content.getSize());// w  w  w  .  j  a  v  a2  s .  c o  m
    }
    return n;
}

From source file:com.stratuscom.harvester.deployer.CommandLineAppRunner.java

private FileObject findServiceArchiveForName(String appName) throws FileSystemException {
    // Locate the service archive that has the client's name.
    // First get all the jar files.
    List<FileObject> serviceArchives = Utils.findChildrenWithSuffix(deploymentDirectoryFile,
            com.stratuscom.harvester.Strings.JAR);
    //Then find the one that starts with the client name
    for (FileObject fo : serviceArchives) {
        if (fo.getName().getBaseName().startsWith(appName + com.stratuscom.harvester.Strings.DASH)) {
            return fo;
        }/*  w ww  .  j  av  a  2s . c o m*/
    }
    return null;
}

From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java

public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn)
        throws IOException {
    try {//from w  w w  .j av a 2  s . c o m
        FileObject fileObject = fsManager.resolveFile(ftpconn, opts);
        FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER));
        HashMap<String, String> parentMap = new HashMap<String, String>();
        for (FileObject fo : files) {
            String objectName = fo.getName().toString();
            tree.addItem(objectName);
            tree.setItemIcon(objectName, FOLDER);
            if (fo.getParent() != null) {
                String parentName = fo.getParent().getName().toString();
                parentMap.put(objectName, parentName);
            } else
                tree.setItemCaption(objectName, "/");
        }

        // set parents
        logger.log(Level.INFO, "parentMap " + parentMap.size());
        if (parentMap.size() > 0) {
            Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                tree.setParent(pairs.getKey(), pairs.getValue());
                String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length());

                tree.setItemCaption(pairs.getKey(), removeSlash(caption));
                it.remove();
            }
        }
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java

private boolean isScriptFile(final FileObject file) {

    final FileName name = file.getName();

    if (name.getBaseName().endsWith(DOT_GROOVY)) {
        return true;
    }// w  w w .j  av a  2 s  . c  o  m

    return false;

}

From source file:com.streamsets.pipeline.lib.remote.TestFTPRemoteConnector.java

private FileObject createFileObject(String path) {
    FileObject fileObject = Mockito.mock(FileObject.class);
    FileName fn = Mockito.mock(FileName.class);
    Mockito.when(fn.getPath()).thenReturn(path);
    Mockito.when(fileObject.getName()).thenReturn(fn);
    return fileObject;
}

From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java

private void updateScript(final FileObject file) {

    final FileName name = file.getName();

    log.info("New script file found: " + name);

    String script;/*  w ww  . j a  va  2 s.  c  o  m*/

    try {

        final FileContent content = file.getContent();

        script = IOUtil.toString(content.getInputStream());

        content.close();

    } catch (final IOException e) {

        log.warn("Unable to read script file: " + name, e);

        return;

    }

    synchronized (scriptStore) {
        scriptStore.put(getName(name), script);
    }

}

From source file:de.blizzy.backup.vfs.RemoteFileOrFolder.java

@Override
public Set<IFileSystemEntry> list() throws IOException {
    final FileObject fileObject = getFileObject();
    IAction<Set<IFileSystemEntry>> action = new IAction<Set<IFileSystemEntry>>() {
        @Override/* w  ww . j  a  v  a  2 s. c o m*/
        public Set<IFileSystemEntry> run() throws IOException {
            Set<IFileSystemEntry> result = new HashSet<>();
            for (FileObject child : fileObject.getChildren()) {
                result.add(getFileOrFolder(file + "/" + child.getName().getBaseName())); //$NON-NLS-1$
            }
            return result;
        }

        @Override
        public boolean canRetry(IOException e) {
            return location.canRetryAction(e);
        }
    };
    return new ActionRunner<>(action, RemoteLocation.MAX_TRIES, location).run();
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java

protected static FileObject createConflictFile(FileObject targetFile) throws FileSystemException {
    String conflictFileName = targetFile.getName().getBaseName() + "_ovlconflict."
            + targetFile.getName().getExtension();
    targetFile = targetFile.getParent().resolveFile(conflictFileName);
    if (targetFile.exists()) {
        targetFile.delete();/*from  w  w  w  .  j a  v a2s.  c  o m*/
    }
    return targetFile;
}

From source file:com.wipro.ats.bdre.filemon.FileMonitor.java

@Override
public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception {
    FileObject obj = fileChangeEvent.getFile();
    LOGGER.debug("File Created " + obj.getURL());
    String dirPath = obj.getParent().getName().getPath();
    LOGGER.debug("Full path " + obj.getName().getPath());

    //Don't process anything with _archive
    if (dirPath.startsWith(monDir + "/" + archiveDirName)) {
        return;//from   w  ww  .  ja va2s  .c o  m
    }
    //Don't process directory
    if (obj.getType() == FileType.FOLDER) {
        return;
    }

    String fileName = obj.getName().getPath();

    //Checking if the file name matches with the given pattern
    if (fileName.matches(filePattern)) {
        FileContent fc = obj.getContent();
        LOGGER.debug("Matched File Pattern by " + fileName);
        putEligibleFileInfoInMap(fileName, fc);
    }
}