List of usage examples for java.nio.file NoSuchFileException NoSuchFileException
public NoSuchFileException(String file)
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public FtpFileView getFileView(final String name) throws IOException { try {/*from ww w . j a va 2 s. com*/ ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(name); if (files.length == 0) throw new NoSuchFileException(name); if (files.length == 1) return new CommonsNetFtpFileView(files[0]); for (final FTPFile file : files) if (".".equals(file.getName())) return new CommonsNetFtpFileView(file); throw new IllegalStateException(); } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:edu.wpi.checksims.submission.Submission.java
/** * Generate a list of all student submissions from a directory. * * The directory is assumed to hold a number of subdirectories, each containing one student or group's submission * The student/group directories may contain subdirectories with files * * @param directory Directory containing student submission directories * @param glob Match pattern used to identify files to include in submission * @param splitter Tokenizes files to produce Token Lists for a submission * @return Set of submissions including all unique nonempty submissions in the given directory * @throws java.io.IOException Thrown on error interacting with file or filesystem */// w w w .j ava 2 s . c o m static Set<Submission> submissionListFromDir(File directory, String glob, Tokenizer splitter, boolean recursive) throws IOException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!"); checkNotNull(splitter); Set<Submission> submissions = new HashSet<>(); Logger local = LoggerFactory.getLogger(Submission.class); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } // List all the subdirectories we find File[] contents = directory.listFiles(File::isDirectory); for (File f : contents) { try { Submission s = submissionFromDir(f, glob, splitter, recursive); submissions.add(s); if (s.getContentAsString().isEmpty()) { local.warn("Warning: Submission " + s.getName() + " is empty!"); } else { local.debug("Created submission with name " + s.getName()); } } catch (NoMatchingFilesException e) { local.warn("Could not create submission from directory " + f.getName() + " - no files matching pattern found!"); } } return submissions; }
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public EnumSet<AccessMode> getAccess(final String name) throws IOException { try {/*from ww w. j a va 2 s . com*/ ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(name); if (files.length == 0) throw new NoSuchFileException(name); if (files.length == 1) return calculateAccess(files[0]); for (final FTPFile file : files) if (".".equals(file.getName())) return calculateAccess(file); throw new IllegalStateException(); } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:com.streamsets.pipeline.lib.io.LiveFile.java
/** * Creates a <code>LiveFile</code> given a {@link Path}. * * @param path the Path of the LiveFile. The file referred by the Path must exist. * @throws IOException thrown if the LiveFile does not exist. */// w ww . ja va 2s. c om public LiveFile(Path path) throws IOException { Utils.checkNotNull(path, "path"); this.path = path.toAbsolutePath(); if (!Files.isRegularFile(this.path)) { throw new NoSuchFileException(Utils.format("Path '{}' is not a file", this.path)); } BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); headLen = (int) Math.min(HEAD_LEN, attrs.size()); headHash = computeHash(path, headLen); iNode = attrs.fileKey().toString(); }
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public List<String> getDirectoryNames(final String dir) throws IOException { try {/* w w w . j a v a 2 s . c o m*/ ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(dir); if (files.length == 0) throw new NoSuchFileException(dir); if (files.length == 1) handleFailedDirectoryList(dir, files[0]); final List<String> ret = new ArrayList<>(files.length); String name; for (final FTPFile file : files) { name = file.getName(); if (!(".".equals(name) || "..".equals(name))) ret.add(name); } return ret; } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:net.lldp.checksims.submission.Submission.java
/** * Generate a list of all student submissions from a directory. * * The directory is assumed to hold a number of subdirectories, each containing one student or group's submission * The student/group directories may contain subdirectories with files * * @param directory Directory containing student submission directories * @param glob Match pattern used to identify files to include in submission * @param splitter Tokenizes files to produce Token Lists for a submission * @return Set of submissions including all unique nonempty submissions in the given directory * @throws java.io.IOException Thrown on error interacting with file or filesystem *//*from w w w . j a v a2 s . c o m*/ static Set<Submission> submissionListFromDir(File directory, String glob, boolean recursive) throws IOException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!"); Set<Submission> submissions = new HashSet<>(); Logger local = LoggerFactory.getLogger(Submission.class); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } // List all the subdirectories we find File[] contents = directory.listFiles(File::isDirectory); for (File f : contents) { try { Submission s = submissionFromDir(f, glob, recursive); submissions.add(s); if (s.getContentAsString().isEmpty()) { local.warn("Warning: Submission " + s.getName() + " is empty!"); } else { local.debug("Created submission with name " + s.getName()); } } catch (NoMatchingFilesException e) { local.warn("Could not create submission from directory " + f.getName() + " - no files matching pattern found!"); } } return submissions; }
From source file:edu.wpi.checksims.submission.Submission.java
/** * Get a single submission from a directory. * * @param directory Directory containing the student's submission * @param glob Match pattern used to identify files to include in submission * @param splitter Tokenizes files to produce Token List in this submission * @return Single submission from all files matching the glob in given directory * @throws IOException Thrown on error interacting with file *///from ww w. j av a 2 s.co m static Submission submissionFromDir(File directory, String glob, Tokenizer splitter, boolean recursive) throws IOException, NoMatchingFilesException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!"); checkNotNull(splitter); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } // TODO consider verbose logging of which files we're adding to the submission? Set<File> files = getAllMatchingFiles(directory, glob, recursive); return submissionFromFiles(directory.getName(), files, splitter); }
From source file:istata.web.HtmlController.java
@RequestMapping(value = { "/edit \"**", "/edit \"**/**" }) @ResponseBody/*w w w . j ava2s.co m*/ public String edit(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws IOException { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); stataService.saveCmd(path); path = path.substring(7, path.length() - 1); Path dofile = Paths.get(path).toAbsolutePath(); if (dofile.toString().equals(path) && dofile.toFile().exists()) { model.put("content", stataService.loadDoFile(path).getContent()); model.put("title", path); return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "edit.vm", "UTF-8", model); } else { path = stataService.expandPath(path); dofile = Paths.get(path).toAbsolutePath(); if (dofile.toFile().exists()) { response.sendRedirect("/edit \"" + dofile.toAbsolutePath().toString() + "\""); return null; } else { // TODO maybe this can be done more graceful throw new NoSuchFileException(path); } } }
From source file:net.lldp.checksims.submission.Submission.java
/** * Get a single submission from a directory. * * @param directory Directory containing the student's submission * @param glob Match pattern used to identify files to include in submission * @param splitter Tokenizes files to produce Token List in this submission * @return Single submission from all files matching the glob in given directory * @throws IOException Thrown on error interacting with file *//*from ww w. j a va 2s .c o m*/ static Submission submissionFromDir(File directory, String glob, boolean recursive) throws IOException, NoMatchingFilesException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!"); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } // TODO consider verbose logging of which files we're adding to the submission? Set<File> files = getAllMatchingFiles(directory, glob, recursive); return submissionFromFiles(directory.getName(), files); }
From source file:edu.wpi.checksims.submission.Submission.java
/** * Identify all files matching in a single directory. * * @param directory Directory to find files within * @param glob Match pattern used to identify files to include * @return Array of files which match in this single directory *//*from ww w . j av a 2 s .com*/ static File[] getMatchingFilesFromDir(File directory, String glob) throws NoSuchFileException, NotDirectoryException { checkNotNull(directory); checkNotNull(glob); checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty"); PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); if (!directory.exists()) { throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath()); } else if (!directory.isDirectory()) { throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath()); } return directory.listFiles((f) -> matcher.matches(Paths.get(f.getAbsolutePath()).getFileName())); }