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.netflix.imfutility.itunes.inputparameters.ITunesInputParametersValidator.java

private static void validateFile(File file, String fileType) throws ArgumentValidationException {
    if (file != null && !file.isFile()) {
        throw new ArgumentValidationException(
                String.format("%s file '%s' must be an existing file", fileType, file.getAbsolutePath()));
    }/*  w w w  .ja va 2  s. co  m*/
}

From source file:io.fabric8.maven.core.extenvvar.ExternalEnvVarHandler.java

/**
 * Finds all of the environment json schemas and combines them together
 *//*w  ww .ja  va 2 s. c o  m*/
private static JsonSchema loadEnvironmentSchemas(ClassLoader classLoader, String... folderPaths)
        throws IOException {
    JsonSchema answer = null;
    Enumeration<URL> resources = classLoader.getResources(ENVIRONMENT_SCHEMA_FILE);
    while (resources.hasMoreElements()) {
        URL url = resources.nextElement();
        JsonSchema schema = loadSchema(url);
        answer = combineSchemas(answer, schema);
    }
    for (String folderPath : folderPaths) {
        File file = new File(folderPath, ENVIRONMENT_SCHEMA_FILE);
        if (file.isFile()) {
            JsonSchema schema = loadSchema(file);
            answer = combineSchemas(answer, schema);
        }
    }
    return answer;
}

From source file:by.stub.utils.FileUtils.java

public static String asciiFileToString(final String filePath) throws IOException {
    final File contentFile = new File(getDataDirectory(), filePath);

    if (!contentFile.isFile()) {
        throw new IOException(String.format("Could not load file from path: %s", filePath));
    }//from w w w.  j  a v a 2  s  .c  o m

    final String loadedContent = StringUtils.inputStreamToString(new FileInputStream(contentFile));

    return FileUtils.enforceSystemLineSeparator(loadedContent);
}

From source file:de.tudarmstadt.ukp.wikipedia.wikimachine.factory.SpringFactory.java

private static XmlBeanFactory getBeanFactory() {
    File outerContextFile = new File(OUTER_APPLICATION_CONTEXT);
    boolean outerContextFileProper = outerContextFile.exists() && outerContextFile.isFile()
            && outerContextFile.canRead();
    Resource res = (outerContextFileProper) ? new FileSystemResource(outerContextFile)
            : new ClassPathResource(INNER_APPLICATION_CONTEXT);
    return new XmlBeanFactory(res);
}

From source file:io.proleap.cobol.runner.impl.CobolParseTestRunnerImpl.java

protected static boolean isCobolFile(final File inputFile) {
    final String extension = FilenameUtils.getExtension(inputFile.getName()).toLowerCase();
    return inputFile.isFile() && Arrays.asList(cobolFileExtensions).contains(extension);
}

From source file:net.sf.jsignpdf.utils.PKCS11Utils.java

/**
 * Tries to register the sun.security.pkcs11.SunPKCS11 provider with
 * configuration provided in the given file.
 * //from  w w w  . j  a  v a2s  .com
 * @param configPath
 *            path to PKCS#11 provider configuration file
 * @return newly registered PKCS#11 provider name if provider successfully
 *         registered; <code>null</code> otherwise
 */
public static String registerProvider(final String configPath) {
    if (StringUtils.isEmpty(configPath)) {
        return null;
    }
    LOGGER.debug("Registering SunPKCS11 provider from configuration in " + configPath);
    final File cfgFile = new File(configPath);
    final String absolutePath = cfgFile.getAbsolutePath();
    if (cfgFile.isFile()) {
        try {
            Provider pkcs11Provider = (Provider) Class.forName("sun.security.pkcs11.SunPKCS11")
                    .getConstructor(String.class).newInstance(absolutePath);
            Security.addProvider(pkcs11Provider);
            final String name = pkcs11Provider.getName();
            LOGGER.debug("SunPKCS11 provider registered with name " + name);
            return name;
        } catch (Exception e) {
            System.err.println("Unable to register SunPKCS11 security provider.");
            e.printStackTrace();
        }
    } else {
        System.err.println(
                "The PKCS#11 provider is not registered. Configuration file doesn't exist: " + absolutePath);
    }
    return null;
}

From source file:com.symbian.driver.core.processors.EmulatorPostProcessor.java

/**
 * @param lNewFile/*from ww w. j  a  va  2  s. c  om*/
 */
public static final void restoreFile(File lNewFile) {
    LOGGER.info("Restoring old file: " + lNewFile);
    if (lNewFile.isFile()) {
        try {
            if (lNewFile.delete() && !new File(lNewFile.getCanonicalPath() + BACKUP).renameTo(lNewFile)) {
                LOGGER.log(Level.SEVERE, "Could not restore file: " + lNewFile.toString());
            }
        } catch (IOException lIOException) {
            LOGGER.log(Level.SEVERE, "Could not restore file: " + lNewFile.toString(), lIOException);
        }
    } else {
        LOGGER.log(Level.WARNING, "Could not find file to restore: " + lNewFile.toString());
    }
}

From source file:io.cloudslang.lang.compiler.SlangSource.java

public static SlangSource fromFile(File file) {
    Validate.notNull(file, "File cannot be null");
    Validate.isTrue(file.isFile(),
            "File content: " + file.getName() + " doesn't lead to a file, directories are not supported");

    String content;//from w w  w  .  ja  va  2s.  c  om
    try {
        content = readFileToString(file);
    } catch (IOException e) {
        throw new RuntimeException("There was a problem reading the file: " + file.getName(), e);
    }

    String fileName = file.getName();

    String filePath = getCanonicalFilePath(file);

    Extension extension = Extension.findExtension(fileName);
    return new SlangSource(content, fileName, filePath, extension);
}

From source file:io.stallion.secrets.SecretsVault.java

public static Map<String, String> loadIfExists(String appPath) {
    String rawPath = appPath + "/conf/secrets.json";
    String encryptedPath = appPath + "/conf/secrets.json.aes";
    File rawFile = new File(rawPath);
    if (rawFile.isFile()) {
        TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
        };// ww w . ja v  a 2s.co  m
        String json = null;
        try {
            json = FileUtils.readFileToString(rawFile, UTF8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return JSON.parse(json, typeRef);
    }
    if (new File(encryptedPath).isFile()) {
        // Get passphrase
        SecretsVault vault = new SecretsCommandLineManager().loadVault(appPath, secretsSettings);
        if (vault != null) {
            return vault.getSecrets();
        }

    }
    return null;
}

From source file:com.funambol.pushlistener.util.DBHelper.java

/**
 * This method is used to load a file into a string.
 * @param fileName is the name of the file to load.
 * @return it's a string containing the whole file.
 * @throws java.lang.Exception if the file doesn't exist or any error occurs
 * while loading the file/*from  w  ww.ja v a2s .com*/
 */
public static String loadFileAsString(String fileName) throws Exception {
    File sourceFile = new File(fileName);
    if (!sourceFile.exists() || !sourceFile.isFile()) {
        throw new Exception("No file for the given name [" + fileName + "] is found.");
    }
    FileInputStream inputFile = new FileInputStream(sourceFile);
    String script = IOUtils.toString(inputFile);
    IOUtils.closeQuietly(inputFile);
    inputFile = null;
    return script;
}