List of usage examples for java.io File canRead
public boolean canRead()
From source file:com.codercowboy.photo.organizer.service.PhotoIndexer.java
public static Photo indexFile(File f) throws Exception { if (!f.exists()) { throw new IOException("Cannot index file, file does not exist: " + f.getAbsolutePath()); }//from w w w . j ava2 s.c o m if (!f.canRead()) { throw new IOException( "Cannot index file, file is not readable, permission denied:" + f.getAbsolutePath()); } Photo p = new Photo(); p.setName(f.getName()); //TODO: this should be relative path to parent p.setFileRelativePath(f.getAbsolutePath()); p.setFileSize(f.length()); FileInputStream fis = new FileInputStream(f); try { p.setMd5Checksum(DigestUtils.md5Hex(fis)); } finally { fis.close(); } return p; }
From source file:com.ca.dvs.app.dvs_servlet.misc.FileUtil.java
/** * Given a folder, return the main RAML file * <p>/*from w ww.j av a 2 s . c o m*/ * @param folder the folder containing a multi-part RAML * @param targetName the desired RAML file to find in the folder * @return the targetName file if found, or the first RAML file found * @throws FileNotFoundException if no RAML files are found in the folder */ public static File selectRamlFile(File folder, String targetName) throws FileNotFoundException { File selectedFile = null; File[] ramlFiles = RamlUtil.getRamlFiles(folder); if (null != ramlFiles && ramlFiles.length > 0) { for (File f : ramlFiles) { if (f.getName().equalsIgnoreCase(targetName) && f.canRead()) { selectedFile = f; break; } } // If none of the raml files match the base name of the uploaded file, use the first one found if (null == selectedFile) { selectedFile = ramlFiles[0]; } } else { String msg = String.format("No RAML files found in folder - %s", folder.getAbsolutePath()); log.error(msg); throw new FileNotFoundException(msg); } return selectedFile; }
From source file:nl.opengeogroep.filesetsync.client.SyncJobState.java
public static boolean haveCachedFileList(String name) { File f = getFileListCacheFile(name); return f.exists() && f.canRead(); }
From source file:CommandLineInterpreter.java
/** * * * @param file/*from w w w .j ava 2 s . c om*/ * @param guiAlert * @return */ public static boolean checkResources(final File file, final boolean guiAlert) { Scanner input = null; String message = null; try { input = new Scanner(file); while (input.hasNextLine()) { String currentFilePath = input.nextLine().trim(); if (!currentFilePath.isEmpty()) { File currentFile = new File(currentFilePath); if (!currentFile.exists() || !currentFile.canRead() || !currentFile.canWrite()) { message = "Can not read/write resource file:\n\"" + currentFile.getAbsolutePath() + "\""; alert(message, guiAlert); return false; } } } } catch (Exception e) { // TODO: logging e.printStackTrace(); } finally { if (input != null) { input.close(); } } return true; }
From source file:marytts.tools.install.LicenseRegistry.java
private static void loadLocalLicenses() { remote2local = new HashMap<URL, String>(); File downloadDir = new File(System.getProperty("mary.downloadDir", ".")); File licenseIndexFile = new File(downloadDir, "license-index.txt"); if (!licenseIndexFile.canRead()) { return; // nothing to load }// ww w . java 2 s . co m try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(licenseIndexFile), "UTF-8"))) { // Each line in licenseIndexFile is expected to be a pair of local file name (relative to downloadDir) and URL string, // separated by a |(pipe) character. String line; while ((line = br.readLine()) != null) { line = line.trim(); StringTokenizer st = new StringTokenizer(line, "|"); if (!st.hasMoreTokens()) { continue; // skip empty lines } String localFilename = st.nextToken().trim(); if (!st.hasMoreTokens()) { continue; // skip lines that don't contain a | } String remoteURLString = st.nextToken().trim(); File localLicenseFile = new File(downloadDir, localFilename); if (!localLicenseFile.canRead()) { System.err.println("License index file " + licenseIndexFile.getAbsolutePath() + " refers to license file " + localLicenseFile.getAbsolutePath() + ", but that file cannot be read. Skipping."); continue; } URL remoteURL = new URL(remoteURLString); remote2local.put(remoteURL, localFilename); } } catch (IOException e) { System.err.println( "Problem reading local license index file " + licenseIndexFile.getAbsolutePath() + ":"); e.printStackTrace(); } }
From source file:android.databinding.tool.LayoutXmlProcessor.java
public static List<File> getLayoutFiles(List<File> resources) { List<File> result = new ArrayList<File>(); for (File resource : resources) { if (!resource.exists() || !resource.canRead()) { continue; }/*from w w w . j a va 2 s.co m*/ if (resource.isDirectory()) { for (File layoutFolder : resource.listFiles(layoutFolderFilter)) { for (File xmlFile : layoutFolder.listFiles(xmlFileFilter)) { result.add(xmlFile); } } } else if (xmlFileFilter.accept(resource.getParentFile(), resource.getName())) { result.add(resource); } } return result; }
From source file:com.autentia.common.util.FileSystemUtils.java
/** * Devuelve el path completo donde se encuentra el fichero <tt>fileName</tt>. Este fichero <tt>fileName</tt> se * busca en el la lista de directorios definida por <tt>searchPath</tt>. Esta es un lista de directorios del estilo * del PATH o del LD_LIBRARY_PATH, es decir una lista de directorios donde el separador es ';' en Windows o ':' en * Unix./* w w w . j a va2s . c o m*/ * * @see File#pathSeparatorChar * @param searchPath lista de directorios del estilo del PATH o del LD_LIBRARY_PATH, es decir una lista de * directorios donde el separador es ';' en Windows o ':' en Unix * @param fileName nombre del fichero que se quiere buscar en <tt>searchPath</tt>. * @return el path completo donde se encuentra el fichero <tt>fileName</tt>. * @throws MissingResourceException si no se encuentra <tt>fileName</tt> en ningn direcotorio definido por * <tt>searchPath</tt>. */ public static String searchFileInPath(String searchPath, String fileName) { final String[] paths = searchPath.split(File.pathSeparator); for (int i = 0; i < paths.length; i++) { String filePath = paths[i]; if (!filePath.endsWith(File.separator)) { filePath += File.separator; } filePath += fileName; if (log.isDebugEnabled()) log.trace("Searching: " + filePath); final File propertiesFile = new File(filePath); if (propertiesFile.canRead()) { if (log.isDebugEnabled()) log.trace("Found and is readable: " + filePath); return filePath; } } throw new MissingResourceException( "Cannot find file '" + fileName + "' in path '" + searchPath + "', or cannot be read", FileSystemUtils.class.getName(), fileName); }
From source file:com.prowidesoftware.swift.utils.Lib.java
/** * Read the content of the given file into a string. * * @param file the file to be read/*from ww w . j av a 2s . c om*/ * @param encoding encoding to use * @return the file contents or null if file is null or does not exist, or can't be read, or is not a file * @throws IOException if an error occurs during read */ public static String readFile(final File file, final String encoding) throws IOException { if (file == null || !file.exists() || !file.canRead() || !file.isFile()) { return null; } BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)); final StringBuilder sb = new StringBuilder((int) file.length()); try { int c = 0; while ((c = in.read()) != -1) { sb.append((char) c); } } finally { in.close(); } return sb.toString(); }
From source file:OS.java
/** * Returns the first readable and writable application data folder appropriate * to this OS./*from ww w .j av a 2s . c o m*/ */ public static File getAppDataFolder() { File[] folders = listAppDataFolders(); for (int i = 0; i < folders.length; i++) { File folder = folders[i]; if (folder.canRead() && folder.canWrite()) return folder; } return null; }
From source file:OS.java
/** * Returns the first readable and writable user data folder appropriate to * this OS.//w ww .ja v a 2s . c om */ public static File getUserDataFolder() { File[] folders = listUserDataFolders(); for (int i = 0; i < folders.length; i++) { File folder = folders[i]; if (folder.canRead() && folder.canWrite()) return folder; } return null; }