List of usage examples for java.io File canRead
public boolean canRead()
From source file:com.threewks.thundr.view.velocity.ServletContextResourceLoader.java
/** * Checks to see when a resource was last modified * //w w w .j av a 2 s.c o m * @param resource Resource the resource to check * @return long The time when the resource was last modified or 0 if the file can't be read */ @Override public long getLastModified(Resource resource) { String rootPath = servletContext.getRealPath("/"); if (rootPath == null) { // rootPath is null if the servlet container cannot translate the // virtual path to a real path for any reason (such as when the // content is being made available from a .war archive) return 0; } File cachedFile = getCachedFile(rootPath, resource.getName()); if (cachedFile.canRead()) { return cachedFile.lastModified(); } else { return 0; } }
From source file:com.fileanalyzer.FileAnalyzer.java
private void iterateFiles(final File dir) { File[] files = dir.listFiles(); if (files == null) { files = new File[1]; files[0] = dir;/* w w w .ja v a 2 s .c o m*/ } for (File file : files) { if (withSubdirectories && file.isDirectory() && file.canRead()) { iterateFiles(file); } else if (pattern.matcher(file.getName()).matches()) { log.info("Finded a file for analyting: " + file.getPath()); ++numFiles; pool.submit(new FileRunnable(file)); } } }
From source file:eu.optimis.vc.api.IsoCreator.IsoImageCreation.java
/** * Directory is valid if it exists, does not represent a file, and can be * read./*from w w w . java 2 s. com*/ * * TODO: Move this to a utils class... */ private static void validateDirectory(File aDirectory) throws FileNotFoundException { if (aDirectory == null) { throw new IllegalArgumentException("Directory should not be null."); } if (!aDirectory.exists()) { throw new FileNotFoundException("Directory does not exist: " + aDirectory); } if (!aDirectory.isDirectory()) { throw new IllegalArgumentException("Is not a directory: " + aDirectory); } if (!aDirectory.canRead()) { throw new IllegalArgumentException("Directory cannot be read: " + aDirectory); } }
From source file:com.evolveum.midpoint.tools.ninja.ImportDDL.java
public boolean execute() { System.out.println("Starting DDL import."); File script = new File(config.getFilePath()); if (!script.exists() || !script.canRead()) { System.out/* w ww . j a va2 s. c om*/ .println("DDL script file '" + script.getAbsolutePath() + "' doesn't exist or can't be read."); return false; } Connection connection = null; BufferedReader reader = null; try { connection = createConnection(); if (connection == null) { return false; } readScript(script, reader, connection); } catch (Exception ex) { System.out.println("Exception occurred, reason: " + ex.getMessage()); ex.printStackTrace(); } finally { IOUtils.closeQuietly(reader); try { if (connection != null && !connection.isClosed()) { connection.close(); } } catch (Exception ex) { System.out.println("Couldn't close JDBC connection, reason: " + ex.getMessage()); } } System.out.println("DDL import finished."); return true; }
From source file:eu.openanalytics.rpooli.RPooliContext.java
@Override protected InputStream getInputStream(final String path) throws IOException { // try first with a file path final File file = new File(path); if (file.isFile() && file.canRead()) { return new FileInputStream(file); } else {/* w w w .j a v a 2s . co m*/ // fallback to web-app embedded files return this.servletContext.getResourceAsStream(path); } }
From source file:de.rkl.tools.tzconv.configuration.PreferencesProvider.java
public File getPreferredTemplateFile() { final String preferredTemplateFilePath = applicationPreferences.get(PREFERENCES_KEY_TEMPLATE_FILE_PATH, null);//www .j a va 2 s.c o m final File templateFile; if (isBlank(preferredTemplateFilePath)) { templateFile = null; } else { final File rawTemplateFile = new File(preferredTemplateFilePath); if (rawTemplateFile.exists() && rawTemplateFile.isFile() && rawTemplateFile.canRead()) { templateFile = rawTemplateFile; } else { templateFile = null; } } return templateFile; }
From source file:org.chimi.s4s.storage.localfs.LocalFSFileStorageUnitTest.java
@Test public void save() { File file = new File("src/test/resources/temp.sql"); FileId fileId = storage.save(file);//www. java2s.c om // ? String separator = System.getProperty("file.separator"); String filePath = FilePathUtil.getDirectoryPath(fileId) + separator + fileId.toString(); File savedFile = new File(basePath, filePath); assertTrue(savedFile.exists()); assertTrue(savedFile.isFile()); assertTrue(savedFile.canRead()); }
From source file:org.pentaho.pat.server.util.JdbcDriverFinder.java
public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcDriverPath);// w ww. j a v a 2 s . co m Assert.notNull(resourceLoader); for (String currentPath : this.jdbcDriverPath) { final Resource res = resourceLoader.getResource(currentPath); if (res == null || !res.exists()) { continue; } final File currentFile = res.getFile(); if (!currentFile.isDirectory() || !currentFile.canRead()) { continue; } this.jdbcDriverDirectory.add(currentFile); if (preLoad) { registerDrivers(); } } if (this.jdbcDriverDirectory.size() == 0) { LOG.warn(Messages.getString("Util.JdbcDriverFinder.NoDriversInPath")); //$NON-NLS-1$ } }
From source file:de.awtools.basic.file.AWToolsFileUtilsTest.java
@Test public void testCreateFilePath() { AWToolsFileUtils.createFilePath(TMP_DIR, TEST_FILE); File dir = new File(TMP_DIR + TEST_DIR); assertThat(dir).isDirectory();//from w w w . j a v a 2 s . c o m assertThat(dir.canRead()).isTrue(); assertThat(dir.canWrite()).isTrue(); }
From source file:mitm.application.djigzo.ws.impl.JamesManagerWSImpl.java
private FileLineNumberReader getReader(String searchPattern) throws FileNotFoundException { Pattern regExpr = null;/*w w w .j av a2 s .c o m*/ if (searchPattern != null && searchPattern.length() > 0) { regExpr = Pattern.compile(searchPattern); } Collection<File> files = new ArrayList<File>(logFiles.size()); for (String logFile : logFiles) { File file = new File(logFile); if (file.exists() && file.canRead()) { files.add(file); } } FileLineNumberReader reader = null; if (files.size() > 0) { reader = new FilteredFileLineNumberReader(files, regExpr); } return reader; }