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

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

Introduction

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

Prototype

int delete(FileSelector selector) throws FileSystemException;

Source Link

Document

Deletes all descendants of this file that match a selector.

Usage

From source file:fi.mystes.synapse.mediator.vfs.VFSTestHelper.java

public static void deleteDirectory(String dirPath) throws FileSystemException {
    FileObject dir = VFS.getManager().resolveFile(dirPath);
    dir.delete(new AllFileSelector());
    dir.delete();/*from w  w w .j ava  2  s  .  c  om*/
}

From source file:hadoopInstaller.installation.UploadConfiguration.java

private void uploadConfiguration(FileObject remoteDirectory, Host host) throws InstallationError {
    try {// ww w . j  a  v  a2 s .c om
        FileObject configurationDirectory = remoteDirectory.resolveFile("hadoop/etc/hadoop/"); //$NON-NLS-1$
        if (deleteOldFiles) {
            configurationDirectory.delete(new AllFileSelector());
            log.debug("HostInstallation.Upload.DeletingOldFiles", //$NON-NLS-1$
                    host.getHostname());
        } else if (!configurationDirectory.exists()) {
            throw new InstallationError("HostInstallation.Upload.NotDeployed"); //$NON-NLS-1$
        }
        configurationDirectory.copyFrom(filesToUpload, new AllFileSelector());
        modifyEnvShFile(host, configurationDirectory, InstallerConstants.ENV_FILE_HADOOP);
        modifyEnvShFile(host, configurationDirectory, InstallerConstants.ENV_FILE_YARN);
        try {
            configurationDirectory.close();
        } catch (FileSystemException ex) {
            log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$
                    configurationDirectory.getName().getURI());
        }
    } catch (FileSystemException e) {
        throw new InstallationError(e, "HostInstallation.Upload.Error", //$NON-NLS-1$
                remoteDirectory.getName().getURI());
    }
}

From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java

/**
 * Does an 'rm' command./*from w ww.  j  a  v a  2  s.c o m*/
 * @param cmd
 * @throws java.lang.Exception
 */
public 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:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java

/**
 * Delete all descendents of this file that match a selector.
 * /*from  www .  j  av  a2  s  . c om*/
 * @param file the file
 * @param selector the selector
 * 
 * @return true, if successful
 * @throws MotuException
 */
public boolean delete(FileObject file, FileSelector selector) throws MotuException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("delete(FileObject, FileSelector) - entering");
    }

    int deleted = 0;
    try {
        if (file.exists()) {
            deleted = file.delete(selector);
        }
    } catch (FileSystemException e) {
        LOG.error("delete(FileObject, FileSelector)", e);

        // throw new MotuException(String.format("Unable to copy file '%s' to '%s'",
        // foSrc.getURL().toString(), foDest.getURL().toString()), e);
        throw new MotuException(String.format("Unable to delete '%s'", file.getName().toString()), e);
    }
    boolean returnboolean = (deleted > 0);
    if (LOG.isDebugEnabled()) {
        LOG.debug("delete(FileObject, FileSelector) - exiting");
    }
    return returnboolean;
}

From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java

public void deleteFSDesignResource(RemoteSession session, String path) throws WGAServiceException {
    if (!isAdminServiceEnabled()) {
        throw new WGAServiceException("Administrative services are disabled");
    }/*from w w  w. j a v  a  2s . c  o m*/

    if (!isAdminSession(session)) {
        throw new WGAServiceException("You need an administrative login to access this service.");
    }

    WGADesignSource source = _core.getDesignManager().getDesignSources()
            .get(WGAConfiguration.UID_DESIGNSOURCE_FILESYSTEM);
    if (source instanceof FileSystemDesignSource) {
        FileSystemDesignSource fsSource = (FileSystemDesignSource) source;
        try {
            fsSource.getDir().refresh();
            FileObject resource = fsSource.getDir().resolveFile(path);

            String basePath = fsSource.getDir().getURL().getPath();
            String resourcePath = resource.getURL().getPath();
            if (!resourcePath.startsWith(basePath)) {
                throw new WGAServiceException(
                        new IllegalArgumentException("Illegal design resource path '" + path + "'."));
            }

            if (resource.exists()) {
                resource.delete(new FileSelector() {

                    public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
                        return true;
                    }

                    public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
                        return true;
                    }

                });
                clearDesignFileCache(fsSource, fsSource.getDir().getName().getRelativeName(resource.getName()));
            }
        } catch (FileSystemException e) {
            throw new WGAServiceException("Deleting FSDesignResource '" + path + "' failed.", e);
        }
    }
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private void doDeleteStoreFile(int storeId, String path)
        throws FileSystemException, SQLException, DAOException, WTException {
    SharingLinkDAO dao = SharingLinkDAO.getInstance();
    FileObject tfo = null;
    Connection con = null;/* ww w  . j  ava 2 s. c o  m*/

    try {
        tfo = getTargetFileObject(storeId, path);

        logger.debug("Deleting store file [{}, {}]", storeId, path);

        try {
            con = WT.getConnection(SERVICE_ID, false);

            dao.deleteByStorePath(con, storeId, path);
            tfo.delete(Selectors.SELECT_ALL);
            DbUtils.commitQuietly(con);

        } catch (FileSystemException ex1) {
            DbUtils.rollbackQuietly(con);
            throw ex1;
        } finally {
            DbUtils.closeQuietly(con);
        }

    } finally {
        IOUtils.closeQuietly(tfo);
    }
}

From source file:org.apache.commons.vfs2.example.Shell.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 = mgr.resolveFile(cwd, cmd[1]);
    file.delete(Selectors.SELECT_SELF);
}

From source file:org.apache.olingo.fit.utils.FSManager.java

public void deleteEntity(final String relativePath) {
    final String path = getAbsolutePath(relativePath, null);
    LOG.info("Delete {}", path);

    try {//  w w w .j  a v  a2  s  .c  o  m
        final FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path);

        if (fileObject.exists()) {
            fileObject.delete(new FileSelector() {
                @Override
                public boolean includeFile(final FileSelectInfo fileInfo) throws Exception {
                    return true;
                }

                @Override
                public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception {
                    return true;
                }
            });
        }
    } catch (IOException ignore) {
        // ignore exception
    }
}

From source file:org.apache.zeppelin.notebook.repo.OldVFSNotebookRepo.java

@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
    FileObject rootDir = fsManager.resolveFile(getPath("/"));
    FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);

    if (!noteDir.exists()) {
        // nothing to do
        return;/*from w  w w  .ja v a  2  s  .c  om*/
    }

    if (!isDirectory(noteDir)) {
        // it is not look like zeppelin note savings
        throw new IOException("Can not remove " + noteDir.getName().toString());
    }

    noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN);
}

From source file:org.apache.zeppelin.notebook.repo.VFSNotebookRepo.java

@Override
public void remove(String noteId) throws IOException {
    FileObject rootDir = fsManager.resolveFile(getPath("/"));
    FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);

    if (!noteDir.exists()) {
        // nothing to do
        return;/*  ww  w  .j  av a  2 s .c o  m*/
    }

    if (!isDirectory(noteDir)) {
        // it is not look like zeppelin note savings
        throw new IOException("Can not remove " + noteDir.getName().toString());
    }

    noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN);
}