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.frostwire.android.gui.util.FileUtils.java

public static void deleteFolderRecursively(File folder) {
    if (folder != null && folder.isDirectory() && folder.canWrite()) {
        //delete your contents and recursively delete sub-folders
        File[] listFiles = folder.listFiles();

        if (listFiles != null) {
            for (File f : listFiles) {
                if (f.isFile()) {
                    f.delete();//  w  ww  .  j  a va 2 s .  co m
                } else if (f.isDirectory()) {
                    deleteFolderRecursively(f);
                }
            }
            folder.delete();
        }
    }
}

From source file:com.glaf.template.config.TemplateConfig.java

public static void reload() {
    if (!loading.get()) {
        InputStream inputStream = null;
        try {//from   w w w.j a v a 2s  .  c  o  m
            loading.set(true);
            String config = SystemProperties.getConfigRootPath() + "/conf/templates/";
            logger.debug("load config dir:" + config);
            File directory = new File(config);
            if (directory.exists() && directory.isDirectory()) {
                TemplateReader reader = new TemplateReader();
                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(".xml")) {
                            logger.debug("read config:" + filename);
                            inputStream = new FileInputStream(file);
                            List<Template> templates = reader.readTemplates(inputStream);
                            if (templates != null && !templates.isEmpty()) {
                                for (Template template : templates) {
                                    if (template.getName() != null) {
                                        concurrentMap.put(template.getName().toLowerCase(), template);
                                    }
                                    if (template.getTemplateId() != null) {
                                        concurrentMap.put(template.getTemplateId().toLowerCase(), template);
                                    }
                                }
                            }
                            IOUtils.closeStream(inputStream);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        } finally {
            loading.set(false);
            IOUtils.closeStream(inputStream);
        }
    }
}

From source file:com.publicuhc.pluginframework.util.YamlUtil.java

/**
 * Loads the yaml from the harddrive//www. j  ava  2  s. c  om
 *
 * @param path the path inside the directory
 * @param dir the directory to check in
 * @return optional, present if file found, absent if not
 * @throws IOException
 * @throws InvalidConfigurationException if file failed to parse
 */
public static Optional<YamlConfiguration> loadYamlFromDir(String path, File dir)
        throws IOException, InvalidConfigurationException {
    Validate.notNull(path, "Path to file cannot be null");

    File file = new File(dir, path);

    if (!file.isFile()) {
        return Optional.absent();
    }

    String fileContent = Files.toString(file, Charsets.UTF_8);

    return Optional.of(loadYamlFromString(fileContent));
}

From source file:net.padaf.preflight.TestIsartorValidationFromClasspath.java

@BeforeClass
public static void beforeClass() throws Exception {
    validator = new PdfAValidatorFactory().createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);

    String irp = System.getProperty("isartor.results.path");
    if (irp != null) {
        File f = new File(irp);
        if (f.exists() && f.isFile()) {
            f.delete();/*from www. j  av  a2  s .com*/
            isartorResultFile = new FileOutputStream(f);
        } else if (!f.exists()) {
            isartorResultFile = new FileOutputStream(f);
        } else {
            throw new IllegalArgumentException("Invalid result file : " + irp);
        }
    }
}

From source file:FileUtil.java

/**
 * Gets the content from a File as StringArray List.
 *
 * @param fileName A file to read from.//from w w  w . j av  a2 s.  c o m
 * @return List of individual line of the specified file. List may be empty but not
 *         null.
 * @throws IOException
 */
public static ArrayList getFileContent(String fileName) throws IOException {
    ArrayList result = new ArrayList();

    File aFile = new File(fileName);

    if (!aFile.isFile()) {
        //throw new IOException( fileName + " is not a regular File" );
        return result; // None
    }

    BufferedReader reader = null;

    try {
        reader = new BufferedReader(new FileReader(aFile));
    } catch (FileNotFoundException e1) {
        // TODO handle Exception
        e1.printStackTrace();

        return result;
    }

    String aLine = null;

    while ((aLine = reader.readLine()) != null) {
        result.add(aLine + "\n");
    }

    reader.close();

    return result;
}

From source file:com.justgiving.raven.kissmetrics.utils.KissmetricsLocalSchemaExtractor.java

/****
 * This function parses all the json record files in a folder and returns a counts of the total occurrences of keys
 * in all files//from w w w . jav  a 2  s .c  o m
 * 
 * @param inputFolder
 * @param outputFolder
 * @throws IOException
 */
private static void countKeysInJsonRecordsFolder(String inputFolder, String outputFile) throws IOException {
    File folder = new File(inputFolder);
    File[] listOfFiles = folder.listFiles();
    KeyValueCounter totalKeyValueCounter = new KeyValueCounter();
    KeyValueCounter currentKeyValueCounter = new KeyValueCounter();
    for (File currentFile : listOfFiles) {
        if (currentFile.isFile()) {
            logger.info("Processing file: " + currentFile.getName());
            currentKeyValueCounter = countKeysInJsonRecordsFile(
                    Paths.get(inputFolder, currentFile.getName()).toString());
            totalKeyValueCounter = deepMergeKeyValueCounter(totalKeyValueCounter, currentKeyValueCounter);
        } else if (currentFile.isDirectory()) {
            logger.warn("Sub-directory folders are currently ignored");
        }
    }
    //System.out.println(totalKeyCounter.toString());
    logger.info("---------------");
    logger.info(sortOutputByKey(totalKeyValueCounter));
    logger.info("saving output to file: ");
    File outpuFile = new File(outputFile);
    outpuFile.getParentFile().mkdirs();
    PrintWriter out = new PrintWriter(outputFile);
    out.print(sortOutputByKey(totalKeyValueCounter));
    out.close();
}

From source file:com.idega.util.FileLocalizer.java

public static void readFile(File fileToRead, Properties props) {
    BufferedReader in = null;/*from   w w  w.  ja  v  a  2 s . c o m*/
    try {
        if (fileToRead.isFile()) {
            in = new BufferedReader(new FileReader(fileToRead));
            String input = in.readLine();
            StringTokenizer st;
            String a, b;
            while (input != null) {
                int index = input.indexOf(stringToFind);
                if (index > -1) {
                    int i1 = input.indexOf("(", index);
                    int i2 = input.indexOf(")", index);
                    if (i2 > -1) {
                        a = input.substring(i1 + 2, i2 - 1);
                        b = "";
                        st = new StringTokenizer(a, "\",");
                        if (st.hasMoreTokens()) {
                            a = st.nextToken();
                            if (st.hasMoreTokens()) {
                                b = st.nextToken();
                            }
                            if (!props.containsKey(a)) {
                                props.setProperty(a, b);

                                // System.err.println(a+"="+b);
                            }
                        }
                    }
                }
                input = in.readLine();
            } // while ends
        } else {
            return;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.timeinc.seleniumite.environment.EnvironmentUtils.java

public static List<RawTestScript> findRawTestScripts(List<String> roots) {
    List<RawTestScript> scripts = new LinkedList<>();

    for (String s : roots) {
        if (s.startsWith("classpath:")) {
            File root = new File(
                    EnvironmentUtils.class.getResource(s.substring("classpath:".length())).getFile());

            Collection<File> matchFiles = FileUtils.listFiles(root, new WildcardFileFilter("*.json"),
                    DirectoryFileFilter.DIRECTORY);

            for (File f : matchFiles) {
                if (f.exists() && f.isFile()) {
                    scripts.add(RawTestScript.fromFile(f));
                } else {
                    LOG.info("Skipping {} - doesn't exist or isnt a file");
                }/*from   ww  w . j  a  v a2s  . c  o m*/
            }
        } else {
            LOG.warn("Skipping unknown protocol:{}", s);
        }
    }

    return scripts;
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreIssueFilter.java

static List<IssuePattern> loadPatterns(final Configuration configuration) {
    if (configuration == null) {
        return Collections.emptyList();
    }/* w  ww.j  av  a2 s  .  c o m*/

    final String fileLocation = configuration.getString(CONFIG_FILE);
    if (StringUtils.isBlank(fileLocation)) {
        LOGGER.info("no ignore file configured for property: {}", CONFIG_FILE);
        return Collections.emptyList();
    }

    final File ignoreFile = new File(fileLocation);
    if (!ignoreFile.isFile()) {
        LOGGER.error("could not find ignore file: {}", ignoreFile);
        return Collections.emptyList();
    }

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(ignoreFile);
        final List<IssuePattern> patterns = IssuePattern.parse(fis);
        LOGGER.info("loaded {} violation ignores from {}", patterns.size(), ignoreFile);
        return patterns;
    } catch (final Exception e) {
        throw new SonarException("could not load ignores for file: " + ignoreFile, e);
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:me.ineson.testing.utils.GradleConfig.java

private static synchronized String readGradleConfig(String key) {
    if (GRADLE_PROPERTIES == null) {
        File filename = new File(SystemUtils.getUserHome(), ".gradle/gradle.properties");
        if (!filename.exists() || !filename.isFile() || !filename.canRead()) {
            throw new IllegalStateException("Failed to access gradle configuration: "
                    + filename.getAbsolutePath() + ", exists " + filename.exists() + ", isFile "
                    + filename.isFile() + ", canRead " + filename.canRead());
        }/*from   w  w  w . j a  v a  2 s. c om*/
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(filename));
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(
                    "Failed to access gradle configuration: " + filename.getAbsolutePath(), e);
        } catch (IOException e) {
            throw new IllegalStateException(
                    "Failed to access gradle configuration: " + filename.getAbsolutePath(), e);
        }
        GRADLE_PROPERTIES = properties;
    }

    String fullKey = "systemProp." + key;
    String value = GRADLE_PROPERTIES.getProperty(fullKey);

    if (value != null) {
        System.setProperty(key, value);
    }

    return value;
}