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:net.hedges.fandangled.commandline.GenericCli.java

private static void checkFilesAndDirectories(File inputFile, File outputDir, File templateDir) {
    if (!inputFile.isFile() || !inputFile.exists()) {
        usage();/* w  w  w.  j a va 2 s.com*/
        throw new RuntimeException("idl file " + inputFile + " doesn't exist or isn't a file");
    }

    if (!templateDir.isDirectory() || !templateDir.exists()) {
        usage();
        throw new RuntimeException("template directory " + templateDir + " doesn't exist or isn't a directory");
    }

    outputDir.mkdirs();
    if (outputDir.isFile() || !outputDir.exists()) {
        usage();
        throw new RuntimeException("output directory " + outputDir + " is a file or doesn't exist");
    }

    if (verbose) {
        System.out.println("template: " + templateDir.getAbsolutePath());
        System.out.println("input: " + inputFile.getAbsolutePath());
        System.out.println("output: " + outputDir.getAbsolutePath());
    }
}

From source file:Main.java

/**
 * get all the dex path/*from   www.ja  va 2  s . co  m*/
 *
 * @param context the application context
 * @return all the dex path
 */
public static List<String> getSourcePaths(Context context)
        throws PackageManager.NameNotFoundException, IOException {
    ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(),
            0);
    File sourceApk = new File(applicationInfo.sourceDir);
    File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME);

    List<String> sourcePaths = new ArrayList<String>();
    sourcePaths.add(applicationInfo.sourceDir); //add the default apk path

    //the prefix of extracted file, ie: test.classes
    String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT;
    //the total dex numbers
    int totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, 1);

    for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++) {
        //for each dex file, ie: test.classes2.zip, test.classes3.zip...
        String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX;
        File extractedFile = new File(dexDir, fileName);
        if (extractedFile.isFile()) {
            sourcePaths.add(extractedFile.getAbsolutePath());
            //we ignore the verify zip part
        } else {
            throw new IOException("Missing extracted secondary dex file '" + extractedFile.getPath() + "'");
        }
    }

    return sourcePaths;
}

From source file:com.flysystem.core.adapter.local.FileCommands.java

private static void validateIsFileAndExists(File file) throws FileNotFoundException {
    if (!file.exists() || !file.isFile())
        throw new FileNotFoundException(file.getPath());
}

From source file:com.pnf.jebauto.AutoUtil.java

/**
 * Create an Apache properties object out of a JEB2 configuration file.
 * /*from   www . j av  a 2  s  .  c  om*/
 * @param path path to a JEB2 configuration file, such as jeb-client.cfg or jeb-engines.cfg
 * @return
 */
public static PropertiesConfiguration createPropertiesConfiguration(String path) {
    File configfile = new File(path);

    if (!configfile.isFile()) {
        try {
            configfile.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
            PropertiesConfiguration.class).configure(params.properties().setFileName(path));
    builder.setAutoSave(true);

    try {
        return builder.getConfiguration();
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.megatronking.svg.cli.Main.java

private static void svg2vectorForDirectory(File inputDir, File outputDir, int width, int height) {
    File[] childFiles = inputDir.listFiles();
    if (childFiles != null) {
        for (File childFile : childFiles) {
            if (childFile.isFile() && childFile.length() > 0) {
                svg2vectorForFile(childFile,
                        new File(outputDir, FileUtils.noExtensionLastName(childFile) + ".xml"), width, height);
            }/*w w  w  .j  a v  a 2 s  .c o m*/
        }
    }
}

From source file:com.github.ibole.infrastructure.security.key.PemUtils.java

private static byte[] parsePEMFile(File pemFile) throws IOException {
    if (!pemFile.isFile() || !pemFile.exists()) {
        throw new FileNotFoundException(
                String.format("The file '%s' doesn't exist.", pemFile.getAbsolutePath()));
    }//from  w ww. j  a  va  2  s. c o m
    PemReader reader = null;
    PemObject pemObject;
    try {
        reader = new PemReader(new FileReader(pemFile));
        pemObject = reader.readPemObject();
    } finally {
        IOUtils.closeQuietly(reader);
    }
    return pemObject.getContent();
}

From source file:com.sap.prd.mobile.ios.mios.XCodeTest.java

private static void getPomFiles(File root, final Set<File> pomFiles) {
    if (root.isFile())
        return;/*from  w w w .j  ava  2 s.c o m*/

    pomFiles.addAll(Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            // here we have the implicit assumtion that a pom file is named "pom.xml".
            // In case we introduce any test with a diffent name for a pom file we have
            // to revisit that.
            return f.isFile() && f.getName().equals("pom.xml");
        }

    })));

    for (File f : Arrays.asList(root.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory();
        }
    })))
        getPomFiles(f, pomFiles);
}

From source file:Main.java

public static Bitmap getBitmapFromDisk(String url, Context ctx) {

    Bitmap defautBitmap = null;/*  ww  w.  j  a  v a  2  s.  co m*/
    try {
        String filename = constructFileName(url);
        File filePath = new File(ctx.getCacheDir(), filename);

        if (filePath.exists() && filePath.isFile() && !filePath.isDirectory()) {
            FileInputStream fi;
            BitmapFactory.Options opts = new BitmapFactory.Options();
            opts.inPreferredConfig = Config.RGB_565;
            fi = new FileInputStream(filePath);
            defautBitmap = BitmapFactory.decodeStream(fi, null, opts);
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();

    } catch (Exception e) {

    } catch (OutOfMemoryError e) {

    }

    return defautBitmap;
}

From source file:Main.java

private static long getSizeOfFileOrDirectoryInByte(File fileOrDirectory) {
    if (!fileOrDirectory.exists()) {
        return 0;
    }/*from  w  w  w.ja v a 2 s . com*/
    if (fileOrDirectory.isFile()) {
        return fileOrDirectory.length();
    }

    File[] contents = fileOrDirectory.listFiles();
    long size = 0;
    for (File file : contents) {
        size += file.isDirectory() ? getSizeOfFileOrDirectoryInByte(file) : file.length();
    }
    return size;
}

From source file:Main.java

public static String getRelativePath(String basePath, String pathToRelativize) throws IOException {
    File baseFile = new File(basePath);
    if (baseFile.isFile()) {
        baseFile = baseFile.getParentFile();
    }//from w w w.  j  av  a 2 s.com

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