@Override public boolean exists(Path f) throws IOException { final File path = pathToFile(f); return path.exists(); }
@Override public boolean rename(final Path src, final Path dst) throws IOException { final File srcFile = pathToFile(src); final File dstFile = pathToFile(dst); final File dstParent = dstFile.getParentFile(); // Files.move fails if the destination directory doesn't exist //noinspection ResultOfMethodCallIgnored -- we don't care if the directory existed or was created dstParent.mkdirs(); try { Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING); return true; } catch (NoSuchFileException | AccessDeniedException | DirectoryNotEmptyException | SecurityException ex) { // catch the errors that are regular "move failed" exceptions and return false return false; } }
@Override public FileStatus getFileStatus(Path f) throws IOException { final File path = pathToFile(f); if (path.exists()) { return new LocalFileStatus(path, this); } else { throw new FileNotFoundException("File " + f + " does not exist or the user running " + "Flink ('" + System.getProperty("user.name") + "') has insufficient permissions to access it."); } }
@Override public FSDataInputStream open(final Path f) throws IOException { final File file = pathToFile(f); return new LocalDataInputStream(file); }
@Override public boolean delete(final Path f, final boolean recursive) throws IOException { final File file = pathToFile(f); if (file.isFile()) { return file.delete(); } else if ((!recursive) && file.isDirectory()) { File[] containedFiles = file.listFiles(); if (containedFiles == null) { throw new IOException("Directory " + file.toString() + " does not exist or an I/O error occurred"); } else if (containedFiles.length != 0) { throw new IOException("Directory " + file.toString() + " is not empty"); } } return delete(file); }
@Override public RecoverableFsDataOutputStream open(Path filePath) throws IOException { final File targetFile = fs.pathToFile(filePath); final File tempFile = generateStagingTempFilePath(targetFile); // try to create the parent final File parent = tempFile.getParentFile(); if (parent != null && !parent.mkdirs() && !parent.exists()) { throw new IOException("Failed to create the parent directory: " + parent); } return new LocalRecoverableFsDataOutputStream(targetFile, tempFile); }
/** * Recursively creates the directory specified by the provided path. * * @return <code>true</code>if the directories either already existed or have been created successfully, * <code>false</code> otherwise * @throws IOException * thrown if an error occurred while creating the directory/directories */ @Override public boolean mkdirs(final Path f) throws IOException { checkNotNull(f, "path is null"); return mkdirsInternal(pathToFile(f)); }
@Override public FileStatus[] listStatus(final Path f) throws IOException { final File localf = pathToFile(f); FileStatus[] results; if (!localf.exists()) { return null; } if (localf.isFile()) { return new FileStatus[] { new LocalFileStatus(localf, this) }; } final String[] names = localf.list(); if (names == null) { return null; } results = new FileStatus[names.length]; for (int i = 0; i < names.length; i++) { results[i] = getFileStatus(new Path(f, names[i])); } return results; }
@Override public FSDataOutputStream create(final Path filePath, final WriteMode overwrite) throws IOException { checkNotNull(filePath, "filePath"); if (exists(filePath) && overwrite == WriteMode.NO_OVERWRITE) { throw new FileAlreadyExistsException("File already exists: " + filePath); } final Path parent = filePath.getParent(); if (parent != null && !mkdirs(parent)) { throw new IOException("Mkdirs failed to create " + parent); } final File file = pathToFile(filePath); return new LocalDataOutputStream(file); }
@Override public boolean exists(Path f) throws IOException { final File path = pathToFile(f); return path.exists(); }
@Override public boolean exists(Path f) throws IOException { final File path = pathToFile(f); return path.exists(); }
@Override public FileStatus getFileStatus(Path f) throws IOException { final File path = pathToFile(f); if (path.exists()) { return new LocalFileStatus(path, this); } else { throw new FileNotFoundException("File " + f + " does not exist or the user running " + "Flink ('" + System.getProperty("user.name") + "') has insufficient permissions to access it."); } }
@Override public FSDataInputStream open(final Path f) throws IOException { final File file = pathToFile(f); return new LocalDataInputStream(file); }
@Override public FileStatus getFileStatus(Path f) throws IOException { final File path = pathToFile(f); if (path.exists()) { return new LocalFileStatus(path, this); } else { throw new FileNotFoundException("File " + f + " does not exist or the user running " + "Flink ('" + System.getProperty("user.name") + "') has insufficient permissions to access it."); } }
@Override public FSDataInputStream open(final Path f) throws IOException { final File file = pathToFile(f); return new LocalDataInputStream(file); }
@Override public RecoverableFsDataOutputStream open(Path filePath) throws IOException { final File targetFile = fs.pathToFile(filePath); final File tempFile = generateStagingTempFilePath(targetFile); // try to create the parent final File parent = tempFile.getParentFile(); if (parent != null && !parent.mkdirs() && !parent.exists()) { throw new IOException("Failed to create the parent directory: " + parent); } return new LocalRecoverableFsDataOutputStream(targetFile, tempFile); }
/** * Recursively creates the directory specified by the provided path. * * @return <code>true</code>if the directories either already existed or have been created successfully, * <code>false</code> otherwise * @throws IOException * thrown if an error occurred while creating the directory/directories */ @Override public boolean mkdirs(final Path f) throws IOException { checkNotNull(f, "path is null"); return mkdirsInternal(pathToFile(f)); }
/** * Recursively creates the directory specified by the provided path. * * @return <code>true</code>if the directories either already existed or have been created successfully, * <code>false</code> otherwise * @throws IOException * thrown if an error occurred while creating the directory/directories */ @Override public boolean mkdirs(final Path f) throws IOException { checkNotNull(f, "path is null"); return mkdirsInternal(pathToFile(f)); }
@Override public FSDataOutputStream create(final Path filePath, final WriteMode overwrite) throws IOException { checkNotNull(filePath, "filePath"); if (exists(filePath) && overwrite == WriteMode.NO_OVERWRITE) { throw new FileAlreadyExistsException("File already exists: " + filePath); } final Path parent = filePath.getParent(); if (parent != null && !mkdirs(parent)) { throw new IOException("Mkdirs failed to create " + parent); } final File file = pathToFile(filePath); return new LocalDataOutputStream(file); }
@Override public FSDataOutputStream create(final Path filePath, final WriteMode overwrite) throws IOException { checkNotNull(filePath, "filePath"); if (exists(filePath) && overwrite == WriteMode.NO_OVERWRITE) { throw new FileAlreadyExistsException("File already exists: " + filePath); } final Path parent = filePath.getParent(); if (parent != null && !mkdirs(parent)) { throw new IOException("Mkdirs failed to create " + parent); } final File file = pathToFile(filePath); return new LocalDataOutputStream(file); }