Example usage for java.io File isFile

List of usage examples for java.io File isFile

Introduction

In this page you can find the example usage for java.io File isFile.

Prototype

public boolean isFile() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a normal file.

Usage

From source file:com.google.dart.tools.core.internal.util.ResourceUtil.java

/**
 * Return the file resource associated with the given file, or <code>null</code> if the file does
 * not correspond to an existing file resource.
 * //from w w w .  jav  a  2s.  c  om
 * @param file the file representing the file resource to be returned
 * @return the file resource associated with the given file
 */
public static IFile getFile(File file) {
    if (file == null) {
        return null;
    }
    if (!file.isFile()) {
        return null;
    }
    IResource resource = getResource(file);
    if (resource == null) {
        return null;
    }
    if (!resource.exists()) {
        return null;
    }
    return (IFile) resource;
}

From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java

public static List<File> getGnosKeys(BaseConfiguration config) {
    List<File> gnosKeys = new ArrayList();
    Path dir = Paths.get(config.getString("gnosKeys"));
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path item : stream) {
            File file = item.toFile();
            if (file.isFile() && !file.isHidden()) {
                gnosKeys.add(file);/*  w  w  w  .  j a  v a 2 s  . c om*/
            }

        }
    } catch (IOException | DirectoryIteratorException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return gnosKeys;
}

From source file:org.eclipse.oomph.setup.internal.sync.SyncUtil.java

public static void deleteFile(File file) throws IOException {
    if (file.isFile()) {
        if (!file.delete()) {
            throw new IOException("Could not delete file " + file);
        }/*  w  ww  .  ja v  a2s. c  o  m*/
    }
}

From source file:com.glaf.core.config.CustomProperties.java

public static void reload() {
    if (!loading.get()) {
        InputStream inputStream = null;
        try {/*  w w w.j av  a  2s.  c  o  m*/
            loading.set(true);
            String config = SystemProperties.getConfigRootPath() + "/conf/props";
            logger.debug(config);
            File directory = new File(config);
            if (directory.exists()) {
                String[] filelist = directory.list();
                if (filelist != null) {
                    for (int i = 0, len = filelist.length; i < len; i++) {
                        String filename = config + "/" + filelist[i];
                        logger.debug(filename);
                        File file = new File(filename);
                        if (file.isFile() && file.getName().endsWith(".properties")) {
                            logger.info("load properties:" + file.getAbsolutePath());
                            inputStream = new FileInputStream(file);
                            Properties p = PropertiesUtils.loadProperties(inputStream);
                            if (p != null) {
                                Enumeration<?> e = p.keys();
                                while (e.hasMoreElements()) {
                                    String key = (String) e.nextElement();
                                    String value = p.getProperty(key);
                                    properties.setProperty(key, value);
                                    properties.setProperty(key.toLowerCase(), value);
                                    properties.setProperty(key.toUpperCase(), value);
                                }
                            }
                            IOUtils.closeStream(inputStream);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            loading.set(false);
            IOUtils.closeStream(inputStream);
        }
    }
}

From source file:com.ikon.module.db.stuff.FsDataStore.java

/**
 * Purge orphan datastore files helper/*www  . ja va2s . com*/
 */
private static void purgeOrphanFilesHelper(Session session, File dir) throws HibernateException, IOException {
    for (File child : dir.listFiles()) {
        if (child.isFile()) {
            if (session.get(NodeDocumentVersion.class, child.getName()) == null) {
                if (!child.delete()) {
                    log.warn("Could not delete file '" + child.getCanonicalPath() + "'");
                }
            }
        } else if (child.isDirectory()) {
            purgeOrphanFilesHelper(session, child);
        }
    }
}

From source file:org.keycloak.testsuite.util.AdminClientUtil.java

private static SSLContext getSSLContextWithTrustore(File file, String password) throws CertificateException,
        NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException {
    if (!file.isFile()) {
        throw new RuntimeException("Truststore file not found: " + file.getAbsolutePath());
    }/*from   w w  w .  ja  v  a2s  .com*/
    SSLContext theContext = SSLContexts.custom().useProtocol("TLS")
            .loadTrustMaterial(file, password == null ? null : password.toCharArray()).build();
    return theContext;
}

From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java

public static List<File> getWorkInis(BaseConfiguration config) {
    List<File> iniFiles = new ArrayList();
    Path dir = Paths.get(config.getString("wfl_inis"));
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path item : stream) {
            File file = item.toFile();
            if (file.isFile() && file.canRead() && !file.isHidden()) {
                if (!file.getName().endsWith(".ini")) {
                    continue;
                }//from w  w w .  ja  v  a  2s .  c o  m
                iniFiles.add(file);
            }

        }
    } catch (IOException | DirectoryIteratorException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return iniFiles;
}

From source file:net.certiv.antlr.project.util.Utils.java

/**
 * Clears (deletes) all files from the given directory.
 * /*from  www .  j  a va2  s  .co  m*/
 * @param dir
 *            the directory to clear
 * @return true if all files were successfully deleted
 * @throws IOException
 */
public static boolean deleteAllFiles(File dir) throws IOException {
    if (dir == null)
        throw new IllegalArgumentException("Directory cannot be null");
    if (!dir.exists() || !dir.isDirectory())
        throw new IOException("Directory must exist");

    DirectoryStream<Path> ds = Files.newDirectoryStream(dir.toPath());
    int del = 0;
    int tot = 0;
    for (Path p : ds) {
        File f = p.toFile();
        String name = f.getName();
        if (f.isFile()) {
            tot++;
            boolean ok = f.delete();
            if (ok) {
                del++;
            } else {
                Log.warn(Utils.class, "Failed to delete: " + name);
            }
        }
    }
    Log.info(Utils.class, "Deleted " + del + " of " + tot + " files");
    return del == tot;
}

From source file:com.glaf.core.xml.XmlProperties.java

public static void reload() {
    if (!loading.get()) {
        InputStream inputStream = null;
        try {/*from w  w w. j  a  v a2  s.c o  m*/
            loading.set(true);
            String config = SystemProperties.getConfigRootPath() + "/conf/templates/xml";
            File directory = new File(config);
            if (directory.exists() && directory.isDirectory()) {
                String[] filelist = directory.list();
                if (filelist != null) {
                    for (int i = 0, len = filelist.length; i < len; i++) {
                        String filename = config + "/" + filelist[i];
                        File file = new File(filename);
                        if (file.isFile() && file.getName().endsWith(".properties")) {
                            inputStream = new FileInputStream(file);
                            Properties p = PropertiesUtils.loadProperties(inputStream);
                            if (p != null) {
                                Enumeration<?> e = p.keys();
                                while (e.hasMoreElements()) {
                                    String key = (String) e.nextElement();
                                    String value = p.getProperty(key);
                                    properties.setProperty(key, value);
                                    properties.setProperty(key.toLowerCase(), value);
                                    properties.setProperty(key.toUpperCase(), value);
                                }
                            }
                            IOUtils.closeStream(inputStream);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            loading.set(false);
            IOUtils.closeStream(inputStream);
        }
    }
}

From source file:eu.edisonproject.classification.main.BatchMain.java

private static void text2Avro(String inputPath, String outputPath, Properties prop) {
    String stopWordsPath = System.getProperty("stop.words.file");

    if (stopWordsPath == null) {
        stopWordsPath = prop.getProperty("stop.words.file",
                ".." + File.separator + "etc" + File.separator + "stopwords.csv");
    }/*from   ww  w.  jav a 2s. co  m*/
    CharArraySet stopWordArraySet = new CharArraySet(ConfigHelper.loadStopWords(stopWordsPath), true);
    StopWord cleanStopWord = new StopWord(stopWordArraySet);
    StanfordLemmatizer cleanLemmatisation = new StanfordLemmatizer();
    File filesInDir = new File(inputPath);
    for (File f : filesInDir.listFiles()) {
        if (f.isFile() && FilenameUtils.getExtension(f.getName()).endsWith("txt")) {
            ReaderFile rf = new ReaderFile(f.getAbsolutePath());
            String contents = rf.readFile();
            cleanStopWord.setDescription(contents);
            String cleanCont = cleanStopWord.execute().toLowerCase();
            cleanLemmatisation.setDescription(cleanCont);
            cleanCont = cleanLemmatisation.execute();
            WriterFile wf = new WriterFile(outputPath + File.separator + f.getName());
            wf.writeFile(cleanCont);
        }
    }
    //        IDataPrepare dp = new DataPrepare(inputPath, outputPath, stopWordsPath);
    //        dp.execute();

}