List of usage examples for java.io File canRead
public boolean canRead()
From source file:bentolor.grocerylist.persistence.ModelSerializer.java
public GroceryLists deserialize(File sourceFile) { try {/* ww w. j a v a2 s. c o m*/ if (sourceFile.canRead()) return mapper.readValue(sourceFile, GroceryLists.class); else return new GroceryLists(); } catch (IOException e) { throw new IllegalArgumentException("Invalid JSON", e); } }
From source file:com.qatickets.service.ConfigService.java
public boolean isNewInstance() { final File loc = new File(DB_LOCATION); return false == (loc.exists() && loc.canRead()); }
From source file:com.googlecode.flyway.core.util.scanner.FileSystemLocationScanner.java
/** * Finds all the resource names contained in this file system folder. * * @param classPathRootOnDisk The location of the classpath root on disk, with a trailing slash. * @param scanRootLocation The root location of the scan on the classpath, without leading or trailing slashes. * @param folder The folder to look for resources under on disk. * @return The resource names;//w w w . j a v a2 s.c o m * @throws IOException when the folder could not be read. */ /*private -> for testing*/ @SuppressWarnings("ConstantConditions") Set<String> findResourceNamesFromFileSystem(String classPathRootOnDisk, String scanRootLocation, File folder) throws IOException { LOG.debug("Scanning for resources in path: " + folder.getPath() + " (classpath location: " + scanRootLocation + ")"); Set<String> resourceNames = new TreeSet<String>(); File[] files = folder.listFiles(); for (File file : files) { if (file.canRead()) { if (file.isDirectory()) { resourceNames .addAll(findResourceNamesFromFileSystem(classPathRootOnDisk, scanRootLocation, file)); } else { resourceNames.add(toResourceNameOnClasspath(classPathRootOnDisk, file)); } } } return resourceNames; }
From source file:org.eclipse.gemini.blueprint.test.internal.util.FileSystemStorageTest.java
public void testResourceForTempFile() throws Exception { Resource res = storage.getResource(); assertTrue(res.exists());// w w w.j a va 2s .c o m File tempFile = res.getFile(); assertTrue(tempFile.exists()); assertTrue(tempFile.canRead()); assertTrue(tempFile.canWrite()); }
From source file:se.crisp.codekvast.support.web.config.WebServerConfig.java
@Bean public EmbeddedServletContainerFactory servletContainer(Environment environment) { Integer serverPort = environment.getProperty("server.port", Integer.class, 8080); TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); File keystore = new File(KEYSTORE_PATH); if (keystore.canRead() && serverPort != 0) { // Don't configure an SSL port during tests. tomcat.addAdditionalTomcatConnectors(createSslConnector(keystore, computeSslPort(serverPort))); }// w w w. j av a 2s . c o m return tomcat; }
From source file:com.github.riccardove.easyjasub.EasyJaSubInputFromCommand.java
private static File getJMDictFile(EasyJaSubCmdHomeDir homeDir, String fileName) throws EasyJaSubException { if (fileName != null && !isDefault(fileName) && !isEnabled(fileName)) { if (isDisabled(fileName)) { return null; }//from www .j a v a2s .co m File file = new File(fileName); if (!file.exists() || !file.isFile()) { throw new EasyJaSubException("Can not find JMdict file " + fileName); } if (!file.canRead()) { throw new EasyJaSubException("Can not read JMdict file " + fileName); } return file; } if (homeDir != null) { File file = homeDir.getJMDictFile(); if (file != null && file.isFile() && file.canRead()) { return file; } } return null; }
From source file:com.streamsets.datacollector.cluster.BaseClusterProvider.java
private static void doCopyDirectory(File srcDir, File destDir) throws IOException { // code copied from commons-io FileUtils to work around files which cannot be read // recurse//from w ww . j a v a 2 s .co m final File[] srcFiles = srcDir.listFiles(); if (srcFiles == null) { // null if abstract pathname does not denote a directory, or if an I/O error occurs throw new IOException("Failed to list contents of " + srcDir); } if (destDir.exists()) { if (!destDir.isDirectory()) { throw new IOException("Destination '" + destDir + "' exists but is not a directory"); } } else { if (!destDir.mkdirs() && !destDir.isDirectory()) { throw new IOException("Destination '" + destDir + "' directory cannot be created"); } } if (!destDir.canWrite()) { throw new IOException("Destination '" + destDir + "' cannot be written to"); } for (final File srcFile : srcFiles) { final File dstFile = new File(destDir, srcFile.getName()); if (srcFile.canRead()) { // ignore files which cannot be read if (srcFile.isDirectory()) { doCopyDirectory(srcFile, dstFile); } else { try (InputStream in = new FileInputStream((srcFile))) { try (OutputStream out = new FileOutputStream((dstFile))) { IOUtils.copy(in, out); } } } } } }
From source file:com.npower.wurfl.FileWurflSource.java
public InputStream getWurflPatchInputStream() throws IOException { String fileName = source.getAbsolutePath(); if (fileName.matches("(.*)wurfl\\.xml$")) { int fc = fileName.indexOf("wurfl.xml"); String dir = fileName.substring(0, fc); String patchfile = dir + "wurfl_patch.xml"; File f = new File(patchfile); if (f.exists() && f.canRead()) { log.info("potential patchfile: " + patchfile); return new FileInputStream(patchfile); } else {//from w ww . j a v a2 s .c o m log.info("potential patchfile: " + patchfile + " does not exist, or is not readable"); } } return null; }
From source file:net.opentsdb.tsd.GraphHandler.java
/** * Iterate through the class path and look for the Gnuplot helper script. * @return The path to the wrapper script. */// ww w . ja v a 2 s . c o m private static String findGnuplotHelperScript() { final URL url = GraphHandler.class.getClassLoader().getResource(WRAPPER); if (url == null) { throw new RuntimeException("Couldn't find " + WRAPPER + " on the" + " CLASSPATH: " + System.getProperty("java.class.path")); } final String path = url.getFile(); LOG.debug("Using Gnuplot wrapper at {}", path); final File file = new File(path); final String error; if (!file.exists()) { error = "non-existent"; } else if (!file.canExecute()) { error = "non-executable"; } else if (!file.canRead()) { error = "unreadable"; } else { return path; } throw new RuntimeException("The " + WRAPPER + " found on the" + " CLASSPATH (" + path + ") is a " + error + " file... WTF?" + " CLASSPATH=" + System.getProperty("java.class.path")); }
From source file:cz.incad.kramerius.client.tools.IndexConfig.java
public IndexConfig() throws IOException, JSONException { String path = System.getProperty("user.home") + File.separator + ".kramerius4" + File.separator + "k5client" + File.separator + "fields.json"; // File f = new File(path); // if (!f.exists() || !f.canRead()) { // f = FileUtils.toFile(IndexConfig.class.getResource("/cz/incad/kramerius/client/tools/fields.json")); // }//w w w .j a v a2 s. co m File fdef = FileUtils.toFile(IndexConfig.class.getResource("/cz/incad/kramerius/client/tools/fields.json")); String json = FileUtils.readFileToString(fdef, "UTF-8"); fieldsConfig = new JSONObject(json); File f = new File(path); if (f.exists() && f.canRead()) { json = FileUtils.readFileToString(f, "UTF-8"); JSONObject confCustom = new JSONObject(json); Iterator keys = confCustom.keys(); while (keys.hasNext()) { String key = (String) keys.next(); LOGGER.log(Level.INFO, "key {0} will be overrided", key); fieldsConfig.put(key, confCustom.get(key)); } } mappings = fieldsConfig.getJSONObject("mappings"); }