|
@@ -27,10 +27,8 @@ import java.util.Arrays;
|
|
|
import java.util.EnumSet;
|
|
|
import java.util.IdentityHashMap;
|
|
|
import java.util.Iterator;
|
|
|
-import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.NoSuchElementException;
|
|
|
import java.util.Set;
|
|
|
import java.util.Stack;
|
|
|
import java.util.TreeSet;
|
|
@@ -1275,12 +1273,13 @@ public final class FileContext {
|
|
|
* @throws UnexpectedServerException If server implementation throws
|
|
|
* undeclared exception to RPC server
|
|
|
*/
|
|
|
- public Iterator<FileStatus> listStatus(final Path f) throws
|
|
|
+ public RemoteIterator<FileStatus> listStatus(final Path f) throws
|
|
|
AccessControlException, FileNotFoundException,
|
|
|
UnsupportedFileSystemException, IOException {
|
|
|
final Path absF = fixRelativePart(f);
|
|
|
- return new FSLinkResolver<Iterator<FileStatus>>() {
|
|
|
- public Iterator<FileStatus> next(final AbstractFileSystem fs, final Path p)
|
|
|
+ return new FSLinkResolver<RemoteIterator<FileStatus>>() {
|
|
|
+ public RemoteIterator<FileStatus> next(
|
|
|
+ final AbstractFileSystem fs, final Path p)
|
|
|
throws IOException, UnresolvedLinkException {
|
|
|
return fs.listStatusIterator(p);
|
|
|
}
|
|
@@ -1314,12 +1313,13 @@ public final class FileContext {
|
|
|
* @throws UnexpectedServerException If server implementation throws
|
|
|
* undeclared exception to RPC server
|
|
|
*/
|
|
|
- public Iterator<LocatedFileStatus> listLocatedStatus(final Path f) throws
|
|
|
+ public RemoteIterator<LocatedFileStatus> listLocatedStatus(
|
|
|
+ final Path f) throws
|
|
|
AccessControlException, FileNotFoundException,
|
|
|
UnsupportedFileSystemException, IOException {
|
|
|
final Path absF = fixRelativePart(f);
|
|
|
- return new FSLinkResolver<Iterator<LocatedFileStatus>>() {
|
|
|
- public Iterator<LocatedFileStatus> next(
|
|
|
+ return new FSLinkResolver<RemoteIterator<LocatedFileStatus>>() {
|
|
|
+ public RemoteIterator<LocatedFileStatus> next(
|
|
|
final AbstractFileSystem fs, final Path p)
|
|
|
throws IOException, UnresolvedLinkException {
|
|
|
return fs.listLocatedStatus(p);
|
|
@@ -1466,7 +1466,8 @@ public final class FileContext {
|
|
|
return new ContentSummary(status.getLen(), 1, 0);
|
|
|
}
|
|
|
long[] summary = {0, 0, 1};
|
|
|
- Iterator<FileStatus> statusIterator = FileContext.this.listStatus(f);
|
|
|
+ RemoteIterator<FileStatus> statusIterator =
|
|
|
+ FileContext.this.listStatus(f);
|
|
|
while(statusIterator.hasNext()) {
|
|
|
FileStatus s = statusIterator.next();
|
|
|
ContentSummary c = s.isDirectory() ? getContentSummary(s.getPath()) :
|
|
@@ -1626,24 +1627,32 @@ public final class FileContext {
|
|
|
* @throws UnexpectedServerException If server implementation throws
|
|
|
* undeclared exception to RPC server
|
|
|
*/
|
|
|
- public Iterator<LocatedFileStatus> listFiles(
|
|
|
+ public RemoteIterator<LocatedFileStatus> listFiles(
|
|
|
final Path f, final boolean recursive) throws AccessControlException,
|
|
|
FileNotFoundException, UnsupportedFileSystemException,
|
|
|
IOException {
|
|
|
- return new Iterator<LocatedFileStatus>() {
|
|
|
- private Stack<Iterator<LocatedFileStatus>> itors =
|
|
|
- new Stack<Iterator<LocatedFileStatus>>();
|
|
|
- Iterator<LocatedFileStatus> curItor = listLocatedStatus(f);
|
|
|
+ return new RemoteIterator<LocatedFileStatus>() {
|
|
|
+ private Stack<RemoteIterator<LocatedFileStatus>> itors =
|
|
|
+ new Stack<RemoteIterator<LocatedFileStatus>>();
|
|
|
+ RemoteIterator<LocatedFileStatus> curItor = listLocatedStatus(f);
|
|
|
LocatedFileStatus curFile;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * {@inheritDoc}
|
|
|
- * @return {@inheritDog}
|
|
|
- * @throws Runtimeexception if any IOException occurs during traversal;
|
|
|
- * the IOException is set as the cause of the RuntimeException
|
|
|
+ * Returns <tt>true</tt> if the iterator has more files.
|
|
|
+ *
|
|
|
+ * @return <tt>true</tt> if the iterator has more files.
|
|
|
+ * @throws AccessControlException if not allowed to access next
|
|
|
+ * file's status or locations
|
|
|
+ * @throws FileNotFoundException if next file does not exist any more
|
|
|
+ * @throws UnsupportedFileSystemException if next file's
|
|
|
+ * fs is unsupported
|
|
|
+ * @throws IOException for all other IO errors
|
|
|
+ * for example, NameNode is not avaialbe or
|
|
|
+ * NameNode throws IOException due to an error
|
|
|
+ * while getting the status or block locations
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean hasNext() {
|
|
|
+ public boolean hasNext() throws IOException {
|
|
|
while (curFile == null) {
|
|
|
if (curItor.hasNext()) {
|
|
|
handleFileStat(curItor.next());
|
|
@@ -1659,44 +1668,49 @@ public final class FileContext {
|
|
|
/**
|
|
|
* Process the input stat.
|
|
|
* If it is a file, return the file stat.
|
|
|
- * If it is a directory, tranverse the directory if recursive is true;
|
|
|
+ * If it is a directory, traverse the directory if recursive is true;
|
|
|
* ignore it if recursive is false.
|
|
|
* If it is a symlink, resolve the symlink first and then process it
|
|
|
* depending on if it is a file or directory.
|
|
|
* @param stat input status
|
|
|
- * @throws RuntimeException if any io error occurs; the io exception
|
|
|
- * is set as the cause of RuntimeException
|
|
|
+ * @throws AccessControlException if access is denied
|
|
|
+ * @throws FileNotFoundException if file is not found
|
|
|
+ * @throws UnsupportedFileSystemException if fs is not supported
|
|
|
+ * @throws IOException for all other IO errors
|
|
|
*/
|
|
|
- private void handleFileStat(LocatedFileStatus stat) {
|
|
|
- try {
|
|
|
- if (stat.isFile()) { // file
|
|
|
- curFile = stat;
|
|
|
- } else if (stat.isSymlink()) { // symbolic link
|
|
|
- // resolve symbolic link
|
|
|
- FileStatus symstat = FileContext.this.getFileStatus(
|
|
|
- stat.getSymlink());
|
|
|
- if (symstat.isFile() || (recursive && symstat.isDirectory())) {
|
|
|
- itors.push(curItor);
|
|
|
- curItor = listLocatedStatus(stat.getPath());
|
|
|
- }
|
|
|
- } else if (recursive) { // directory
|
|
|
+ private void handleFileStat(LocatedFileStatus stat)
|
|
|
+ throws IOException {
|
|
|
+ if (stat.isFile()) { // file
|
|
|
+ curFile = stat;
|
|
|
+ } else if (stat.isSymlink()) { // symbolic link
|
|
|
+ // resolve symbolic link
|
|
|
+ FileStatus symstat = FileContext.this.getFileStatus(
|
|
|
+ stat.getSymlink());
|
|
|
+ if (symstat.isFile() || (recursive && symstat.isDirectory())) {
|
|
|
itors.push(curItor);
|
|
|
curItor = listLocatedStatus(stat.getPath());
|
|
|
}
|
|
|
- } catch (IOException ioe) {
|
|
|
- throw (RuntimeException)new RuntimeException().initCause(ioe);
|
|
|
+ } else if (recursive) { // directory
|
|
|
+ itors.push(curItor);
|
|
|
+ curItor = listLocatedStatus(stat.getPath());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * {@inheritDoc}
|
|
|
- * @return {@inheritDoc}
|
|
|
- * @throws Runtimeexception if any IOException occurs during traversal;
|
|
|
- * the IOException is set as the cause of the RuntimeException
|
|
|
- * @exception {@inheritDoc}
|
|
|
+ * Returns the next file's status with its block locations
|
|
|
+ *
|
|
|
+ * @throws AccessControlException if not allowed to access next
|
|
|
+ * file's status or locations
|
|
|
+ * @throws FileNotFoundException if next file does not exist any more
|
|
|
+ * @throws UnsupportedFileSystemException if next file's
|
|
|
+ * fs is unsupported
|
|
|
+ * @throws IOException for all other IO errors
|
|
|
+ * for example, NameNode is not avaialbe or
|
|
|
+ * NameNode throws IOException due to an error
|
|
|
+ * while getting the status or block locations
|
|
|
*/
|
|
|
@Override
|
|
|
- public LocatedFileStatus next() {
|
|
|
+ public LocatedFileStatus next() throws IOException {
|
|
|
if (hasNext()) {
|
|
|
LocatedFileStatus result = curFile;
|
|
|
curFile = null;
|
|
@@ -1704,12 +1718,6 @@ public final class FileContext {
|
|
|
}
|
|
|
throw new java.util.NoSuchElementException("No more entry in " + f);
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void remove() {
|
|
|
- throw new UnsupportedOperationException("Remove is not supported");
|
|
|
-
|
|
|
- }
|
|
|
};
|
|
|
}
|
|
|
|