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:io.wcm.devops.conga.generator.util.FileUtil.java

/**
 * Ensure that file exists./*from  w  w  w  .j a va  2 s.  co m*/
 * @param file File
 * @return File
 */
public static File ensureFileExists(File file) {
    if (!file.exists() || !file.isFile()) {
        throw new IllegalArgumentException("File not found: " + getCanonicalPath(file));
    }
    return file;
}

From source file:com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.java

/**
 * Reads the contents of the given source and initiates schema generation.
 * //ww w . j a v a  2  s  .  c  o  m
 * @param config
 *            the configuration options (including source and target paths,
 *            and other behavioural options) that will control code
 *            generation
 * @throws FileNotFoundException
 *             if the source path is not found
 * @throws IOException
 *             if the application is unable to read data from the source
 */
public static void generate(GenerationConfig config) throws FileNotFoundException, IOException {

    Annotator annotator = getAnnotator(config);
    SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, annotator, new SchemaStore()),
            new SchemaGenerator());

    JCodeModel codeModel = new JCodeModel();

    if (config.isRemoveOldOutput()) {
        removeOldOutput(config.getTargetDirectory());
    }

    for (Iterator<File> sources = config.getSource(); sources.hasNext();) {
        File source = sources.next();

        if (source.isDirectory()) {

            List<File> schemaFiles = Arrays.asList(source.listFiles());
            Collections.sort(schemaFiles);

            for (File child : schemaFiles) {
                if (child.isFile()) {
                    mapper.generate(codeModel, getNodeName(child), defaultString(config.getTargetPackage()),
                            child.toURI().toURL());
                }
            }
        } else {
            mapper.generate(codeModel, getNodeName(source), defaultString(config.getTargetPackage()),
                    source.toURI().toURL());
        }
    }

    if (config.getTargetDirectory().exists() || config.getTargetDirectory().mkdirs()) {
        codeModel.build(config.getTargetDirectory(), new NullPrintStream());
    } else {
        throw new GenerationException(
                "Could not create or access target directory " + config.getTargetDirectory().getAbsolutePath());
    }
}

From source file:fr.gael.dhus.util.UnZip.java

public static boolean supported(String file) {
    boolean is_supported = file.toLowerCase().endsWith(".zip")/* ||
                                                              file.toLowerCase ().endsWith (".tar") ||
                                                              file.toLowerCase ().endsWith (".tgz") ||
                                                              file.toLowerCase ().endsWith (".tar.gz")*/;
    File fileObject = new File(file);
    is_supported &= fileObject.exists() && fileObject.isFile();
    return is_supported;
}

From source file:Main.java

public static File getRelativeFile(File baseFile, File fileToRelativize) throws IOException {
    if (baseFile.isFile()) {
        baseFile = baseFile.getParentFile();
    }//from ww  w  .j a  v  a  2  s .  c  o m

    return new File(getRelativeFileInternal(baseFile.getCanonicalFile(), fileToRelativize.getCanonicalFile()));
}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *//* w  ww  .j av a  2s.  c  om*/
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = getBookmarksExportFolder();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().endsWith(".xml"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}

From source file:Main.java

public static Collection<File> listFiles(File dir, FileFilter filter) {
    Collection<File> accumulator = new ArrayList<File>();

    if (dir.isFile()) {
        return accumulator;
    }/* www  .j a va  2 s  .  co m*/

    if (filter == null) {
        // Set default filter to accept any file
        filter = new FileFilter() {
            public boolean accept(File pathname) {
                return true;
            }
        };
    }

    innerListFiles(dir, accumulator, filter);
    return accumulator;
}

From source file:com.qait.automation.samjbehavedemo.utils.FileHandler.java

public static List<String> getFileNames(String filedirpath, final String filenameendswith) {

    List<String> filenames = new ArrayList<>();

    File[] files = getFile(filedirpath).listFiles();

    for (File file : files) {
        String filename = file.getName();
        if (file.isFile() && filename.toLowerCase().endsWith(filenameendswith.toLowerCase())) {
            filenames.add(filename);//from  www.ja  v  a 2  s .c o  m
        }
    }

    if (filenames.isEmpty()) {
        throw new NullPointerException(
                "There are no files matching the criteria in directoy: " + filedirpath.toUpperCase());
    }

    return filenames;
}

From source file:com.ggasoftware.uitest.utils.FileUtil.java

/**
 * Tests whether the file denoted by this abstract pathname is a normal
 * file.  A file is <em>normal</em> if it is not a directory and, in
 * addition, satisfies other system-dependent criteria.  Any non-directory
 * file created by a Java application is guaranteed to be a normal file.
 *
 * @param pathAndFileName - name of file and FULL path for it
 * @return - true if file exists and//from w  w  w  . j ava 2s. com
 * - false if file absence default directory(path) for downloaded files
 * - true if and only if the file denoted by this abstract pathname exists and is a normal file;
 * - false otherwise
 */
public static boolean isFileExist(String pathAndFileName) {
    ReporterNGExt.logTechnical(String.format("isFileExist: %s", pathAndFileName));
    File findFile = new File(pathAndFileName);
    return findFile.isFile();
}

From source file:net.pms.dlna.DVDISOFile.java

private static String getFileName(File file) {
    return file.isFile() ? file.getName() : "VIDEO_TS";
}

From source file:ch.elexis.core.data.util.FileUtility.java

/**
 * berprft, ob eine Datei existiert//from w ww. j a  va  2s . c  o m
 */
public static boolean doesFileExist(final String filePathName) {
    File file = new File(filePathName);
    return file.isFile() && file.exists();
}