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.sap.prd.mobile.ios.ota.lib.OtaHtmlGenerator.java

public static synchronized OtaHtmlGenerator getInstance(String template, boolean forceNewInstance) {
    if (isEmpty(template)) {
        template = DEFAULT_TEMPLATE;/*from  w  w  w.  j  av a2 s  .c  o m*/
    } else {
        File file = new File(template);
        if (file.isFile() && file.getName().equals(DEFAULT_TEMPLATE))
            throw new IllegalArgumentException(format(
                    "Custom template (configured in e.g. 'Tomcat/conf/Catalina/localhost/ota-service.xml') "
                            + "must not be named '%s'. Current path: '%s'",
                    DEFAULT_TEMPLATE, template));
    }

    OtaHtmlGenerator instance;

    if (forceNewInstance || !instances.keySet().contains(template)) {
        instance = new OtaHtmlGenerator(template);
        instances.put(template, instance);
    } else {
        instance = instances.get(template);
    }

    return instance;
}

From source file:com.wabacus.util.FileLockTools.java

public static boolean createLockFile(String lockfile) {
    try {/*  w  w  w . j a  va  2  s  . c o  m*/
        File f = new File(lockfile);
        if (f != null && f.isFile()) {
            f.delete();
        }
        return f.createNewFile();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.openmeetings.app.data.file.FileUtils.java

public static long getSize(File dir) {
    long size = 0;
    if (dir.isFile()) {
        size = dir.length();/*  www.j av  a  2s .  co m*/
    } else {
        File[] subFiles = dir.listFiles();

        for (File file : subFiles) {
            if (file.isFile()) {
                size += file.length();
            } else {
                size += getSize(file);
            }

        }
    }
    return size;
}

From source file:com.stratio.mojo.scala.crossbuild.ITs.java

public static boolean verify(final List<String> scalaBinaryVersions, final List<String> artifactNames,
        final List<String> targetPaths, final List<String> testCases)
        throws IOException, FileNotFoundException {
    if (artifactNames.size() != targetPaths.size()) {
        throw new IllegalArgumentException("artifactNames and modulePaths must be equal size");
    }// w  w  w . j a va2  s. c  o  m
    if (scalaBinaryVersions.isEmpty()) {
        throw new IllegalArgumentException("At least one scalaBinaryVersion must be provided");
    }
    for (final String scalaBinaryVersion : scalaBinaryVersions) {
        for (int i = 0; i < artifactNames.size(); i++) {
            final String artifactName = artifactNames.get(i);
            final String artifactId = artifactName + "_" + scalaBinaryVersion;
            final File targetPath = new File(targetPaths.get(i));
            final File targetScalaPath = new File(targetPath, scalaBinaryVersion);
            final File artifactPath = new File(targetScalaPath, artifactId + "-1.jar");
            if (!artifactPath.isFile()) {
                throw new FileNotFoundException("Could not find generated artifact: " + artifactPath);
            }
            if (testCases.isEmpty()) {
                continue;
            }
            final File surefireReportsPath = new File(targetScalaPath, "surefire-reports");
            if (!surefireReportsPath.isDirectory()) {
                throw new FileNotFoundException(
                        "Could not find surefire-reports directory: " + surefireReportsPath);
            }
            final File[] testReports = surefireReportsPath.listFiles(new FileFilter() {
                @Override
                public boolean accept(final File pathname) {
                    return pathname.getName().endsWith(".xml") && pathname.getName().startsWith("TEST-");
                }
            });
            if (testReports.length == 0) {
                throw new FileNotFoundException("Could not find test reports");
            }
            for (final String testCase : testCases) {
                final String scalaString = "[Scala " + scalaBinaryVersion + "]";
                boolean found = false;
                for (final File testReport : testReports) {
                    final String testReportString = IOUtils.toString(new FileInputStream(testReport));
                    final String testCaseWithSuffix = testCase + " " + scalaString;
                    if (testReportString.contains(testCaseWithSuffix)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new RuntimeException("JUnit XML test report does not contain Scala version string ("
                            + scalaString + ")");
                }
            }
        }
    }
    return true;
}

From source file:com.wabacus.util.FileLockTools.java

public static boolean deleteLockFile(String lockfile) {
    try {/*  w  ww  .  java2s.c o  m*/
        File f = new File(lockfile);
        if (f != null && f.isFile()) {
            f.delete();
            return true;
        }
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static byte[] readBytes(File file) throws IOException {
    //check/*from  w  w w . ja v a 2  s.  c o m*/
    if (!file.exists()) {
        throw new FileNotFoundException("File not exist: " + file);
    }
    if (!file.isFile()) {
        throw new IOException("Not a file:" + file);
    }

    long len = file.length();
    if (len >= Integer.MAX_VALUE) {
        throw new IOException("File is larger then max array size");
    }

    byte[] bytes = new byte[(int) len];
    FileInputStream in = null;
    try {
        in = new FileInputStream(file);
        in.read(bytes);
    } finally {
        close(in);
    }

    return bytes;
}

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

public static byte[] binaryFileToBytes(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 a2 s. c  om

    return IOUtils.toByteArray(new FileInputStream(contentFile));
}

From source file:com.sonicle.webtop.core.app.util.LogbackHelper.java

public static URL findConfigFileURLFromSystemProperties(ClassLoader classLoader) {
    String logbackConfigFile = OptionHelper.getSystemProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
    if (logbackConfigFile != null) {
        URL result = null;/*  ww  w.j  a  va 2s.  c  o m*/
        try {
            result = new URL(logbackConfigFile);
            return result;
        } catch (MalformedURLException e) {
            // so, resource is not a URL:
            // attempt to get the resource from the class path
            result = Loader.getResource(logbackConfigFile, classLoader);
            if (result != null) {
                return result;
            }
            File f = new File(logbackConfigFile);
            if (f.exists() && f.isFile()) {
                try {
                    result = f.toURI().toURL();
                } catch (MalformedURLException e1) {
                }
            }
        }
    }
    return null;
}

From source file:io.apiman.common.config.ConfigFileConfiguration.java

/**
 * Discover the location of the apiman.properties (for example) file by checking
 * in various likely locations./*w ww. ja va  2  s . co m*/
 */
private static URL discoverConfigFileUrl(String configFileName, String customConfigPropertyName) {
    URL rval;

    // User Defined
    ///////////////////////////////////
    String userConfig = System.getProperty(customConfigPropertyName);
    if (userConfig != null) {
        // Treat it as a URL
        try {
            rval = new URL(userConfig);
            return rval;
        } catch (Exception t) {
        }
        // Treat it as a file
        try {
            File f = new File(userConfig);
            if (f.isFile()) {
                rval = f.toURI().toURL();
                return rval;
            }
        } catch (Exception t) {
        }
        throw new RuntimeException(
                "Apiman configuration provided at [" + userConfig + "] but could not be loaded."); //$NON-NLS-1$ //$NON-NLS-2$
    }

    // Wildfly/EAP
    ///////////////////////////////////
    String jbossConfigDir = System.getProperty("jboss.server.config.dir"); //$NON-NLS-1$
    String jbossConfigUrl = System.getProperty("jboss.server.config.url"); //$NON-NLS-1$
    if (jbossConfigDir != null) {
        File dirFile = new File(jbossConfigDir);
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }
    if (jbossConfigUrl != null) {
        File dirFile = new File(jbossConfigUrl);
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }

    // Apache Tomcat
    ///////////////////////
    String tomcatHomeDir = System.getProperty("catalina.home"); //$NON-NLS-1$
    if (tomcatHomeDir != null) {
        File dirFile = new File(tomcatHomeDir, "conf"); //$NON-NLS-1$
        rval = findConfigUrlInDirectory(dirFile, configFileName);
        if (rval != null) {
            return rval;
        }
    }

    // If not found, use an empty file.
    ////////////////////////////////////////
    return ConfigFileConfiguration.class.getResource("empty.properties"); //$NON-NLS-1$
}

From source file:com.kegare.caveworld.plugin.mceconomy.MCEconomyPlugin.java

@Method(modid = MODID)
public static void invoke() {
    File file = new File(Loader.instance().getConfigDir(), "mceconomy2.cfg");

    if (file.isFile() && file.exists()) {
        Configuration config = new Configuration(file);
        ConfigCategory category;//from w w  w  . ja  v a  2 s .  co m

        for (String name : config.getCategoryNames()) {
            category = config.getCategory(name);

            if (category.containsKey("Player_MP_MAX")) {
                Player_MP_MAX = category.get("Player_MP_MAX").getInt(Player_MP_MAX);

                break;
            }
        }
    }

    syncShopCfg();

    MCEconomyAPI.addPurchaseItem(new ItemStack(CaveBlocks.caveworld_portal), 2000);

    if (Config.rope) {
        MCEconomyAPI.addPurchaseItem(new ItemStack(CaveBlocks.rope), 2);
    }

    SHOP = MCEconomyAPI.registerProductList(ShopProductManager.instance());
}