/** * This implementation checks whether the underlying file is marked as readable * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canRead() * @see java.io.File#isDirectory() */ @Override public boolean isReadable() { return (this.file != null ? this.file.canRead() && !this.file.isDirectory() : Files.isReadable(this.filePath) && !Files.isDirectory(this.filePath)); }
public static void checkJarFile(URL jar) throws IOException { File jarFile; try { jarFile = new File(jar.toURI()); } catch (URISyntaxException e) { throw new IOException("JAR file path is invalid '" + jar + "'"); } if (!jarFile.exists()) { throw new IOException("JAR file does not exist '" + jarFile.getAbsolutePath() + "'"); } if (!jarFile.canRead()) { throw new IOException("JAR file can't be read '" + jarFile.getAbsolutePath() + "'"); } // TODO: Check if proper JAR file }
private File loadTxnFile(String txnLogFileName) throws TxnLogToolkitException { File logFile = new File(txnLogFileName); if (!logFile.exists() || !logFile.canRead()) { throw new TxnLogToolkitException(ExitCode.UNEXPECTED_ERROR.getValue(), "File doesn't exist or not readable: %s", logFile); } return logFile; }
protected static File getCVSFile(String parent, String name) { try { File CVSdir = new File(parent, "CVS"); if (CVSdir.isDirectory() && CVSdir.canRead()) { File root = new File(CVSdir, "Root"); if (root.canRead()) { return readCVSRoot(root, CVSdir, name); } } } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to retrieve CVS file of parent: " + parent + ", name: " + name, e); } return null; }
/** * @return true iff the argument is a readable directory */ public static boolean isReadableDir(File d) { return d.exists() && d.isDirectory() && d.canRead(); }
private void expandArgumentFile(String fileName, List<String> arguments, Set<String> visited) { File file = new File(fileName); if (!file.canRead()) { if (tracer.isInfo()) {tracer.info("File %s does not exist or cannot be read; treating argument literally%n", fileName);} arguments.add("@" + fileName); } else if (visited.contains(file.getAbsolutePath())) { if (tracer.isInfo()) {tracer.info("Already visited file %s; ignoring...%n", file.getAbsolutePath());} } else { expandValidArgumentFile(fileName, file, arguments, visited); } } private void expandValidArgumentFile(String fileName, File file, List<String> arguments, Set<String> visited) {
public FileMultipartPart(FilePart part, byte[] boundary) { super(part, boundary); File file = part.getFile(); if (!file.exists()) { throw new IllegalArgumentException("File part doesn't exist: " + file.getAbsolutePath()); } else if (!file.canRead()) { throw new IllegalArgumentException("File part can't be read: " + file.getAbsolutePath()); } length = file.length(); }
logger.trace("Searching directory [" + dir.getAbsolutePath() + "] for files matching pattern [" + fullPattern + "]"); String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/"); if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) { if (!content.canRead()) { if (logger.isDebugEnabled()) { logger.debug("Skipping subdirectory [" + dir.getAbsolutePath() + "] because the application is not allowed to read the directory");
public FilePart(String name, File file, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { super(name, contentType, charset, fileName != null ? fileName : file.getName(), contentId, transferEncoding); if (!assertNotNull(file, "file").isFile()) throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath()); if (!file.canRead()) throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath()); this.file = file; }
@Override public boolean accept(File pathname) { String name = pathname.getName(); return !".".equals(name) && !"..".equals(name) && pathname.canRead() && (pathname.isDirectory() || (pathname.isFile() && checkFileExt(name))); }
private void checkFilesAccessibility(File bundledPlugins, File externalPlugins) { boolean bundled = bundledPlugins.canRead(); boolean external = externalPlugins.canRead(); if (!bundled || !external) { String folder = bundled ? externalPlugins.getAbsolutePath() : bundledPlugins.getAbsolutePath(); LOG.error("Could not read plugins. Please check access rights on files in folder: {}.", folder); throw new FileAccessRightsCheckException(String.format("Could not read plugins. Please make sure that the user running GoCD can access %s", folder)); } }
/** * Validates {@code file} is an existing file that is readable. * * @param file the File to test * @return the provided file, if all validation passes * @throws IllegalArgumentException if validation fails */ private static File validateFile(File file) throws IllegalArgumentException { if (!file.isFile()) { throw new IllegalArgumentException("Path is not a file: " + file); } if (!file.canRead()) { throw new IllegalArgumentException("Unable to read file: " + file); } return file; }
/** * @param filePath the file path to be validated * @return Returns null if valid otherwise error message */ public static String validateFileInput(String filePath) { File file = new File(filePath); if (!file.exists()) { return "File '" + file.getAbsolutePath() + "' does not exist."; } if (!file.canRead()) { return "Read permission is denied on the file '" + file.getAbsolutePath() + "'"; } if (file.isDirectory()) { return "'" + file.getAbsolutePath() + "' is a direcory. it must be a file."; } return null; }
PersistFS(File root) { _root = root; _dir = new File(root, "ice" + H2O.API_PORT); // Make the directory as-needed root.mkdirs(); if( !(root.isDirectory() && root.canRead() && root.canWrite()) ) { Log.die("ice_root not a read/writable directory"); } }