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

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

Introduction

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

Prototype

boolean exists() throws FileSystemException;

Source Link

Document

Determines if this file exists.

Usage

From source file:hadoopInstaller.configurationGeneration.LoadFromFolder.java

@Override
public FileObject generateConfigurationFiles() throws InstallationFatalError {
    FileObject folder;
    this.log.debug("HadoopInstaller.LoadFromFolder.Loading", this.folderName);//$NON-NLS-1$
    try {//from   w w w  . j a va  2 s .c  om
        folder = this.localDirectory.resolveFile(this.folderName);
        if (!folder.exists()) {
            folder.createFolder();
            this.log.warn("HadoopInstaller.LoadFromFolder.FolderDoesntExist", //$NON-NLS-1$
                    this.folderName);
        }
    } catch (FileSystemException e) {
        throw new InstallationFatalError(e, "HadoopInstaller.LoadFromFolder.FolderCouldNotOpen", //$NON-NLS-1$
                this.folderName);
    }
    this.log.debug("HadoopInstaller.LoadFromFolder.Loaded", this.folderName); //$NON-NLS-1$
    return folder;
}

From source file:de.innovationgate.wgpublisher.design.sync.DesignDeployment.java

public void doAttachFile(WGDocument doc, FileObject file) throws WGDesignSyncException {

    try {/*from w ww  .  j  a  v a2s .c o  m*/
        if (!file.exists()) {
            throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '"
                    + doc.getDocumentKey() + "' failed because the file does not exist.");
        }

        if (!doc.attachFile(file.getContent().getInputStream(), file.getName().getBaseName())) {
            throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '"
                    + doc.getDocumentKey() + "' failed.");
        }
    } catch (Exception e) {
        throw new WGDesignSyncException("Attaching file '" + file.getName().getPath() + "' to document '"
                + doc.getDocumentKey() + "' failed.", e);
    }

}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testFileObjectExistDelete() throws Exception {
    String rootPath = System.getProperty("java.io.tmpdir", "/tmp");
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build();
    DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator;

    FileObject fileObject = operatorImpl.getFileObject();
    when(fileObject.exists()).thenReturn(true);

    operatorImpl.delete("/document/1/test.html");

    verify(fileObject, atLeastOnce()).delete();
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testFileObjectNotExistDelete() throws Exception {
    String rootPath = System.getProperty("java.io.tmpdir", "/tmp");
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build();
    DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator;

    FileObject fileObject = operatorImpl.getFileObject();
    when(fileObject.exists()).thenReturn(false);

    operatorImpl.delete("/document/1/test.html");

    verify(fileObject, never()).delete();
}

From source file:hadoopInstaller.installation.UploadConfiguration.java

private String getLocalFileContents(String fileName) throws InstallationError {
    log.debug("HostInstallation.LoadingLocal", //$NON-NLS-1$
            fileName);//from w w w .ja v a 2 s  .c  om
    FileObject localFile;
    String localFileContents = new String();
    try {
        localFile = filesToUpload.resolveFile(fileName);
        if (localFile.exists()) {
            localFileContents = IOUtils.toString(localFile.getContent().getInputStream());
        }
    } catch (IOException e) {
        throw new InstallationError(e, "HostInstallation.CouldNotOpen", //$NON-NLS-1$
                fileName);
    }
    try {
        localFile.close();
    } catch (FileSystemException e) {
        log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$
                localFile.getName().getURI());
    }
    log.debug("HostInstallation.LoadedLocal", //$NON-NLS-1$
            fileName);
    return localFileContents;
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testTestSuccess() throws Exception {
    String rootPath = System.getProperty("java.io.tmpdir", "/tmp");
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build();
    DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator;

    FileObject fileObject = operatorImpl.getRootFileObject();
    when(fileObject.exists()).thenReturn(true);
    when(fileObject.isWriteable()).thenReturn(true);

    Assert.assertTrue(operatorImpl.test());
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testDirNotExistTest() throws Exception {
    String rootPath = System.getProperty("java.io.tmpdir", "/tmp");
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build();
    DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator;

    FileObject fileObject = operatorImpl.getRootFileObject();
    when(fileObject.exists()).thenReturn(false);
    when(fileObject.isWriteable()).thenReturn(true);

    try {/*w ww  .  j  a  v a2 s  . c  o  m*/
        Assert.assertTrue(operatorImpl.test());
        Assert.fail();
    } catch (PublishException e) {
        Assert.assertEquals(e.getMessage(), "error.output.nodir");
    }
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java

@Test
public void testDirNotWriteableTest() throws Exception {
    String rootPath = System.getProperty("java.io.tmpdir", "/tmp");
    DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build();
    DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator;

    FileObject fileObject = operatorImpl.getRootFileObject();
    when(fileObject.exists()).thenReturn(true);
    when(fileObject.isWriteable()).thenReturn(false);

    try {// w w w  . j  a  v a2  s . c o m
        Assert.assertTrue(operatorImpl.test());
        Assert.fail();
    } catch (PublishException e) {
        Assert.assertEquals(e.getMessage(), "error.output.notwrite");
    }
}

From source file:cz.lbenda.dataman.db.ExtConfFactory.java

/** Load extend configuration to given database configuration */
public void load() {
    if (exConf != null && StringUtils.isBlank(exConf.getSrc())) {
        loadExConfType(exConf);// w w w.  ja  v a2 s .  com
    } else if (exConf != null) {
        if (exConf.getSrc().startsWith("db://")) {
            String path = exConf.getSrc().substring(5, exConf.getSrc().length());
            dbConfig.getConnectionProvider()
                    .onPreparedStatement(String.format(
                            "select usr, exConf from %s where (usr = ? or usr is null or usr = '')", path),
                            tuple2 -> {
                                PreparedStatement ps = tuple2.get1();
                                String extendConfiguration = null;
                                try {
                                    ps.setString(1, dbConfig.getConnectionProvider().getUser().getUsername());
                                    try (ResultSet rs = ps.executeQuery()) {
                                        while (rs.next()) {
                                            if (rs.getString(1) == null && extendConfiguration == null) { // The null user is used only if no specific user configuration is read
                                                extendConfiguration = rs.getString(2);
                                            } else if (rs.getString(1) != null) {
                                                extendConfiguration = rs.getString(2);
                                            }
                                        }
                                    }
                                } catch (SQLException e) {
                                    LOG.error("Problem with read extend config from table: " + exConf.getSrc(),
                                            e);
                                    ExceptionMessageFrmController.showException(
                                            "Problem with read extend config from table: " + exConf.getSrc(),
                                            e);
                                }
                                if (!StringUtils.isBlank(extendConfiguration)) {
                                    loadExConfType(new StringReader(extendConfiguration));
                                } else {
                                    StringUtils.isBlank(null);
                                }
                            });
        } else {
            try {
                FileSystemManager fsManager = VFS.getManager();
                FileObject file = fsManager.resolveFile(exConf.getSrc());
                if (!file.exists()) {
                    ExceptionMessageFrmController.showException("File not exist: " + exConf.getSrc());
                } else if (file.getChildren() == null || file.getChildren().length == 0) {
                    new Thread(() -> {
                        try {
                            FileContent content = file.getContent();
                            loadExConfType(new InputStreamReader(content.getInputStream()));
                            content.close();
                        } catch (FileSystemException e) {
                            LOG.error("Problem with read extend config from file: " + exConf.getSrc(), e);
                            ExceptionMessageFrmController.showException(
                                    "Problem with read extend config from file: " + exConf.getSrc(), e);
                        }
                    }).start();
                } else {
                    ExceptionMessageFrmController
                            .showException("The file type isn't supported: " + exConf.getSrc());
                }
            } catch (FileSystemException e) {
                LOG.error("Problem with read extend config from file: " + exConf.getSrc(), e);
                ExceptionMessageFrmController
                        .showException("Problem with read extend config from file: " + exConf.getSrc(), e);
            }
        }
    }
}

From source file:de.innovationgate.utils.DirComparer.java

private void addFileHashes(Map<String, String> hashes, FileObject file, FileObject root)
        throws NoSuchAlgorithmException, IOException {
    if (file == null || !file.exists()) {
        return;//from ww w. ja  v a2 s .  c  o  m
    }
    for (FileObject child : file.findFiles(_fileSelector)) {
        addFileHash(hashes, child, root);
    }
}