List of usage examples for java.io File isFile
public boolean isFile()
From source file:Main.java
private static InputStream createInputStream(String src) throws FileNotFoundException { if (src.startsWith(PREFIX_JAR)) { String name = src.substring(PREFIX_JAR.length()); InputStream inputStream = Thread.currentThread().getClass().getResourceAsStream(name); if (inputStream == null) { throw new FileNotFoundException("resource not found: " + src); }/*from w w w . ja v a 2 s . c om*/ return inputStream; } else if (src.startsWith(PREFIX_FILE)) { File file = new File(src.substring(PREFIX_FILE.length())); if (!file.exists()) { throw new IllegalArgumentException("file does not exist: " + src); } else if (!file.isFile()) { throw new IllegalArgumentException("not a file: " + src); } else if (!file.canRead()) { throw new IllegalArgumentException("cannot read file: " + src); } return new FileInputStream(file); } throw new IllegalArgumentException("invalid bitmap source: " + src); }
From source file:license.regist.ReadProjectInfo.java
static boolean isRight() { BufferedReader br = null;/* w w w . j a v a 2 s .c o m*/ try { File f = new File(registerFile()); if (f.isFile()) { FileReader reader = new FileReader(f); br = new BufferedReader(reader); String info = new Blowfish(Date.class.getName()).decryptString(br.readLine()); String md5 = br.readLine(); Base64 base64 = new Base64(); System.out.println(info.length()); byte[] rmd5 = md5(info); byte[] lmd5 = rsa(base64.decode(md5)); System.out.println(base64.encodeToString(rmd5)); System.out.println(base64.encodeToString(lmd5)); if (equalsBytes(rmd5, lmd5)) { Map infoMap = readInfo(info); if (checkPeriod(infoMap)) { if (type.longValue() < 2L) return true; return (checkCpu(infoMap)) && (checkPath(infoMap)) && (checkMac(infoMap)); } } return false; } } catch (Exception e) { return false; } finally { if (br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:com.magnet.tools.tests.FileSystemStepDefs.java
public static String getFileContentAsString(String filePath) throws IOException { File file = new File(ScenarioUtils.expandVariables(filePath)); Assert.assertTrue("file " + filePath + " should exist", file.exists() && file.isFile()); return FileUtils.readFileToString(file); }
From source file:com.plotsquared.iserver.util.FileUtils.java
/** * Get the size of a file or directory//from w ww. jav a2 s . c o m * * @param file File * @return Size of file */ public static long getSize(final File file) { long size = 0; if (file.isDirectory()) { final File[] files = file.listFiles(); if (files == null) return size; for (final File f : files) if (f.isFile()) size += f.length(); else size += getSize(file); } else if (file.isFile()) size += file.length(); return size; }
From source file:com.glaf.core.config.SystemProperties.java
public static String getSecurityKey(String path) { if (concurrentMap.containsKey(path)) { return concurrentMap.get(path); }/*from w w w .ja v a 2s . co m*/ File file = new File(path); if (file.exists() && file.isFile()) { String content = FileUtils.readFile(path); concurrentMap.put(path, content); } return concurrentMap.get(path); }
From source file:com.magnet.tools.tests.FileSystemStepDefs.java
@Then("^the file \\\"([^\\\"]*)\\\" should exist$") public static void the_file_should_exist(String filepath) throws Throwable { File file = new File(ScenarioUtils.expandVariables(filepath)); Assert.assertTrue("File " + file.getAbsolutePath() + " should be a file", file.isFile()); Assert.assertTrue("File " + file.getAbsolutePath() + " should exist", file.exists()); }
From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java
/** * Returns the classpath as a list of the names of archive files. Any * classpath component that is not an archive will be ignored. * * @return the classpath as a list of archive file names; if no archives can * be found then an empty list will be returned *//*www . j a v a2 s. c om*/ public static List getClasspathArchives() { List archives = new ArrayList(); List components = getClasspathComponents(); for (Iterator i = components.iterator(); i.hasNext();) { String possibleDir = (String) i.next(); File file = new File(possibleDir); if (file.isFile() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) { archives.add(possibleDir); } } return archives; }
From source file:it.geosolutions.geobatch.catalog.file.GeoBatchDataDirAwarePropertyOverrideConfigurer.java
/** * Tries to find the provided properties file and then returns its properties. * /*w w w.j a v a 2 s.co m*/ * @param propertiesFile the {@link File} to load from. Must exists and be readable. * @throws IOException in case something bad happens trying to read the proeprties from the file. * */ protected static Properties loadProperties(final File propertiesFile) throws IOException { // checks on provided file if (!(propertiesFile != null && propertiesFile.exists() && propertiesFile.isFile() && propertiesFile.canRead())) { return null; } // load the file InputStream is = null; try { is = new BufferedInputStream(new FileInputStream(propertiesFile)); final Properties properties = new Properties(); properties.load(is); return properties; } finally { // close if (is != null) { try { is.close(); } catch (Exception e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(e.getLocalizedMessage(), e); } } } } }
From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java
/** * <p>Asserts that the local directory contents have all been deployed to the remote URL prefix.</p> * @param message The message that will be in the error if the local directory hasn't been deployed to the remote URL prefix. * @param directory The directory locally that should have been deployed. * @param urlPrefix The URL prefix that should have the contents of the directory. * @param username The Basic HTTP auth username. * @param password The Basic HTTP auth password. */// ww w . ja va2 s. c om public static void assertContentDeployed(String message, File directory, String urlPrefix, String username, String password) { if (directory == null || !directory.isDirectory() || urlPrefix == null) { throw new AssertionFailedError(message); } File files[] = getAllDirectoryContents(directory, "META-INF", ".git"); String basePath = directory.getAbsoluteFile().getAbsolutePath(); if (urlPrefix.endsWith("/")) { urlPrefix = urlPrefix.substring(0, urlPrefix.length() - 2); } for (File file : files) { if (file.isFile()) { String httpPath = urlPrefix + "/" + file.getAbsoluteFile().getAbsolutePath().replaceFirst(basePath + "/", ""); assertResourcesEqual(message, file, httpPath, username, password); } } }
From source file:com.glaf.core.config.MessageProperties.java
public static void reload() { if (!loading.get()) { InputStream inputStream = null; try {//from ww w . j a v a 2 s . c om loading.set(true); String config = SystemProperties.getConfigRootPath() + "/conf/props/messages"; File directory = new File(config); if (directory.exists() && directory.isDirectory()) { File[] filelist = directory.listFiles(); 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(".properties")) { inputStream = new FileInputStream(file); Properties p = PropertiesUtils.loadProperties(inputStream); if (p != null) { Enumeration<?> e = p.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = p.getProperty(key); properties.setProperty(key, value); properties.setProperty(key.toLowerCase(), value); properties.setProperty(key.toUpperCase(), value); } } IOUtils.closeStream(inputStream); } } } } ISystemPropertyService systemPropertyService = ContextFactory.getBean("systemPropertyService"); List<SystemProperty> list = systemPropertyService.getAllSystemProperties(); if (list != null && !list.isEmpty()) { for (SystemProperty p : list) { properties.put(p.getName(), p); } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { loading.set(false); IOUtils.closeStream(inputStream); } } }