Example usage for org.apache.commons.vfs Selectors SELECT_SELF

List of usage examples for org.apache.commons.vfs Selectors SELECT_SELF

Introduction

In this page you can find the example usage for org.apache.commons.vfs Selectors SELECT_SELF.

Prototype

FileSelector SELECT_SELF

To view the source code for org.apache.commons.vfs Selectors SELECT_SELF.

Click Source Link

Document

A FileSelector that selects only the base file/folder.

Usage

From source file:net.didion.loopy.vfs.provider.iso.IsoFileSystem.java

public void init() throws FileSystemException {
    super.init();

    final File file = getParentLayer().getFileSystem().replicateFile(getParentLayer(), Selectors.SELECT_SELF);

    try {/*from w ww . j  a v  a2 s . co m*/
        this.fileSystem = new ISO9660FileSystem(file, true);
    } catch (IOException ex) {
        throw new FileSystemException("vfs.provider.iso/open-iso-file.error", file, ex);
    }

    // Build the index
    final List strongRef = new ArrayList(100);

    final Enumeration entries = this.fileSystem.getEntries();

    while (entries.hasMoreElements()) {
        final ISO9660FileEntry entry = (ISO9660FileEntry) entries.nextElement();

        String name = entry.getPath();

        // skip entries without names (should only be one - the root entry)
        if ("".equals(name)) {
            continue;
        }

        final FileName filename = getFileSystemManager().resolveName(getRootName(), UriParser.encode(name));

        // Create the file
        IsoFileObject fileObj;

        if (entry.isDirectory() && getFileFromCache(filename) != null) {
            fileObj = (IsoFileObject) getFileFromCache(filename);
            fileObj.setIsoEntry(entry);
            continue;
        }

        fileObj = new IsoFileObject(filename, entry, this);
        putFileToCache(fileObj);
        strongRef.add(fileObj);
        fileObj.holdObject(strongRef);

        // Make sure all ancestors exist
        IsoFileObject parent;

        for (FileName parentName = filename
                .getParent(); parentName != null; fileObj = parent, parentName = parentName.getParent()) {

            // Locate the parent
            parent = (IsoFileObject) getFileFromCache(parentName);

            if (parent == null) {
                parent = new IsoFileObject(parentName, this);
                putFileToCache(parent);
                strongRef.add(parent);
                parent.holdObject(strongRef);
            }

            // Attach child to parent
            parent.attachChild(fileObj.getName());
        }
    }
}

From source file:com.github.stephenc.javaisotools.vfs.provider.iso.IsoFileSystem.java

public void init() throws FileSystemException {
    super.init();

    final File file = getParentLayer().getFileSystem().replicateFile(getParentLayer(), Selectors.SELECT_SELF);

    try {//from www.  j  a va  2 s.  co  m
        this.fileSystem = new Iso9660FileSystem(file, true);
    } catch (IOException ex) {
        throw new FileSystemException("vfs.provider.iso/open-iso-file.error", file, ex);
    }

    // Build the index
    final List strongRef = new ArrayList(100);

    boolean skipRoot = false;

    for (Iso9660FileEntry entry : this.fileSystem) {

        String name = entry.getPath();

        // skip entries without names (should only be one - the root entry)
        if ("".equals(name)) {
            if (!skipRoot) {
                skipRoot = true;
            } else {
                continue;
            }
        }

        final FileName filename = getFileSystemManager().resolveName(getRootName(), UriParser.encode(name));

        // Create the file
        IsoFileObject fileObj;

        if (entry.isDirectory() && getFileFromCache(filename) != null) {
            fileObj = (IsoFileObject) getFileFromCache(filename);
            fileObj.setIsoEntry(entry);
            continue;
        }

        fileObj = new IsoFileObject(filename, entry, this);
        putFileToCache(fileObj);
        strongRef.add(fileObj);
        fileObj.holdObject(strongRef);

        // Make sure all ancestors exist
        IsoFileObject parent;

        for (FileName parentName = filename
                .getParent(); parentName != null; fileObj = parent, parentName = parentName.getParent()) {

            // Locate the parent
            parent = (IsoFileObject) getFileFromCache(parentName);

            if (parent == null) {
                parent = new IsoFileObject(parentName, this);
                putFileToCache(parent);
                strongRef.add(parent);
                parent.holdObject(strongRef);
            }

            // Attach child to parent
            parent.attachChild(fileObj.getName());
        }
    }
}

From source file:gov.nih.nci.cacis.ip.mirthconnect.ftp.SFTPSender.java

public void sendDocument(InputStream file, String ftpAddress, String extension) {

    StandardFileSystemManager standardFileSystemManager = new StandardFileSystemManager();
    try {/*from  ww w. ja v a 2 s . c  o  m*/
        final FTPInfo ftpInfo = ftpMapping.getFTPInfo(ftpAddress);
        if (ftpInfo == null) {
            throw new ApplicationRuntimeException("No server config exists for address[ " + ftpAddress + " ]");
        }

        String sftpURI = "sftp://" + ftpInfo.getUserName() + ":" + ftpInfo.getPassword() + "@"
                + ftpInfo.getSite() + "/" + ftpInfo.getRootDirectory();
        String fileName = "IHEXIPFTP-" + UUID.randomUUID() + extension;

        FileSystemOptions fileSystemOptions = new FileSystemOptions();
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fileSystemOptions, "no");
        SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(fileSystemOptions, true);

        standardFileSystemManager.init();

        FileObject fileObject = standardFileSystemManager.resolveFile(sftpURI + "/" + fileName,
                fileSystemOptions);

        long timestamp = new Date().getTime();
        String tempSftpFile = sftpFileDirectory + "/" + timestamp + ".xml";
        OutputStream out = new FileOutputStream(new File(tempSftpFile));

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = file.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        file.close();
        out.flush();
        out.close();

        FileObject localFileObject = standardFileSystemManager.resolveFile(tempSftpFile);

        fileObject.copyFrom(localFileObject, Selectors.SELECT_SELF);

        FileUtils.forceDelete(new File(tempSftpFile));

    } catch (Exception e) {
        throw new ApplicationRuntimeException("Error sending SFTP. " + e.getMessage());
    } finally {
        standardFileSystemManager.close();
    }
}

From source file:com.naryx.tagfusion.expression.function.file.FileCopy.java

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    String srcFile = parameters.get(1).getString();
    String destFile = parameters.get(0).getString();

    /* Src File */
    cfVFSData vfsSrc = null;//  w  ww . j  a va 2  s .  com
    try {
        vfsSrc = new cfVFSData(srcFile);
    } catch (Exception e) {
        throwException(_session, "File [" + srcFile + "] caused an error (" + e.getMessage() + ")");
        return cfBooleanData.FALSE;
    }

    /* Dest File */
    cfVFSData vfsDest = null;
    try {
        vfsDest = new cfVFSData(destFile);
    } catch (Exception e) {
        throwException(_session, "File [" + destFile + "] caused an error (" + e.getMessage() + ")");
        return cfBooleanData.FALSE;
    } finally {
        try {
            vfsSrc.close();
        } catch (Exception e) {
        }
    }

    /* Attempt the copy */
    try {

        if (!vfsSrc.isNative() && !vfsDest.isNative())
            vfsDest.getFileObject().copyFrom(vfsSrc.getFileObject(), Selectors.SELECT_SELF);
        else
            copy(vfsSrc, vfsDest);

    } catch (Exception e) {
        throwException(_session, "Copying file caused an error (" + e.getMessage() + ")");
        return cfBooleanData.FALSE;
    } finally {
        try {
            vfsSrc.close();
        } catch (Exception e) {
        }
        try {
            vfsDest.close();
        } catch (Exception e) {
        }
    }

    return cfBooleanData.TRUE;
}

From source file:functionalTests.multiprotocol.TestVFSProviderMultiProtocol.java

/**
 * Testing the File server deployment using multi-protocol
 * @throws Exception/*  w w  w .  ja v a 2 s  . c  o m*/
 */
@Test
public void testVFSProviderMP() throws Exception {

    logger.info("**************** Testing deploying dataspace server with protocol list : " + protocolsToTest);

    CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.setValue(protocolsToTest.get(0));
    String add_str = protocolsToTest.get(1);
    for (int i = 2; i < protocolsToTest.size(); i++) {
        add_str += "," + protocolsToTest.get(i);
    }
    CentralPAPropertyRepository.PA_COMMUNICATION_ADDITIONAL_PROTOCOLS.setValue(add_str);

    FileSystemServerDeployer deployer = new FileSystemServerDeployer("space name",
            SERVER_PATH.getAbsolutePath(), true);

    try {

        String[] urls = deployer.getVFSRootURLs();
        logger.info("Received urls :" + Arrays.asList(urls));
        Assert.assertEquals(
                "Number of urls of the FileSystemServerDeployer should match the number of protocols + the file protocol",
                protocolsToTest.size() + 1, urls.length);

        // check the file server uris

        URI receiveduri = new URI(urls[0]);
        Assert.assertEquals("protocol of first uri " + receiveduri + " should be file", "file",
                receiveduri.getScheme());

        for (int i = 1; i < urls.length; i++) {
            receiveduri = new URI(urls[i]);
            Assert.assertEquals("protocol of uri " + urls[i] + " should match the expected protocol",
                    "pap" + protocolsToTest.get(i - 1), receiveduri.getScheme());
        }

        // use the file server
        for (int i = 0; i < urls.length; i++) {
            File f = new File(System.getProperty("java.io.tmpdir"), "testfile_" + i);
            f.createNewFile();
            logger.info("Trying to use : " + urls[i]);
            FileObject source = fileSystemManager.resolveFile(f.toURI().toURL().toExternalForm());
            FileObject dest = fileSystemManager.resolveFile(urls[i] + "/" + f.getName());
            dest.copyFrom(source, Selectors.SELECT_SELF);
            Assert.assertTrue("Copy successful of " + source.getURL() + " to " + dest.getURL(), dest.exists());

        }

    } finally {
        deployer.terminate();
    }

}

From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java

private void testFindFiles(FileObject rootObject) throws Exception {
    FileObject[] findFiles = rootObject.findFiles(Selectors.EXCLUDE_SELF);
    findFiles = rootObject.findFiles(Selectors.SELECT_ALL);
    findFiles = rootObject.findFiles(Selectors.SELECT_CHILDREN);
    findFiles = rootObject.findFiles(Selectors.SELECT_FILES);
    findFiles = rootObject.findFiles(Selectors.SELECT_FOLDERS);
    findFiles = rootObject.findFiles(Selectors.SELECT_SELF);
    findFiles = rootObject.findFiles(Selectors.SELECT_SELF_AND_CHILDREN);
}

From source file:com.newatlanta.appengine.nio.file.GaePath.java

@Override
public Path copyTo(Path target, CopyOption... options) throws IOException {
    if (!(target instanceof GaePath)) {
        throw new ProviderMismatchException();
    }//  w ww . ja va 2  s  . c  o  m
    checkAccess(AccessMode.READ);
    Set<CopyOption> optionSet = checkCopyOptions(options);
    if (isSameFile(target, optionSet.contains(REPLACE_EXISTING))) {
        return target;
    }
    if (fileObject.getType().hasChildren()) {
        target.deleteIfExists(); // fails for non-empty directory
        target.createDirectory();
    } else {
        ((GaePath) target).fileObject.copyFrom(fileObject, Selectors.SELECT_SELF);
        if (optionSet.contains(COPY_ATTRIBUTES)) {
            ((GaePath) target).fileObject.getContent()
                    .setLastModifiedTime(fileObject.getContent().getLastModifiedTime());
        }
    }
    return target;
}

From source file:org.apache.commons.vfs.example.Shell.java

/**
 * Does an 'rm' command./*from   www .java  2 s. co  m*/
 */
private void rm(final String[] cmd) throws Exception {
    if (cmd.length < 2) {
        throw new Exception("USAGE: rm <path>");
    }

    final FileObject file = mgr.resolveFile(cwd, cmd[1]);
    file.delete(Selectors.SELECT_SELF);
}

From source file:org.codehaus.mojo.unix.core.FsFileCollector.java

private Callable packageFile(final FileObject from, final UnixFsObject.RegularFile to) {
    return new Callable() {
        public Object call() throws Exception {
            FileObject toFile = root.resolveFile(to.path.string);

            toFile.getParent().createFolder();
            toFile.copyFrom(from, Selectors.SELECT_SELF);
            toFile.getContent().setLastModifiedTime(to.lastModified.toDateTime().toDate().getTime());
            return Unit.unit();
        }/* w w  w.j  ava2 s .  c o m*/
    };
}

From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java

/**
 * Does an 'rm' command.//w  w  w .j a v a  2  s .  c  o  m
 */
private void rm(final String[] cmd) throws Exception {
    if (cmd.length < 2) {
        throw new Exception("USAGE: rm <path>");
    }

    final FileObject file = remoteMgr.resolveFile(remoteCwd, cmd[1]);
    file.delete(Selectors.SELECT_SELF);
}