HADOOP-8910. Add examples to GlobExpander#expand method. Contributed by Suresh Srinivas.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1397691 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2012-10-12 19:03:10 +00:00
parent 22ef03bc76
commit 611ff4ec89
3 changed files with 35 additions and 20 deletions

View File

@ -122,6 +122,8 @@ Trunk (Unreleased)
HADOOP-8864. Addendum to HADOOP-8840: Add a coloring case for +0 results HADOOP-8864. Addendum to HADOOP-8840: Add a coloring case for +0 results
too. (harsh) too. (harsh)
HADOOP-8910. Add examples to GlobExpander#expand method. (suresh)
BUG FIXES BUG FIXES
HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName. HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.

View File

@ -1391,11 +1391,11 @@ public abstract class FileSystem extends Configured implements Closeable {
} }
final private static PathFilter DEFAULT_FILTER = new PathFilter() { final private static PathFilter DEFAULT_FILTER = new PathFilter() {
@Override @Override
public boolean accept(Path file) { public boolean accept(Path file) {
return true; return true;
} }
}; };
/** /**
* List the statuses of the files/directories in the given path if the path is * List the statuses of the files/directories in the given path if the path is
@ -1559,17 +1559,16 @@ public abstract class FileSystem extends Configured implements Closeable {
} }
/** /**
* Return an array of FileStatus objects whose path names match pathPattern * Return an array of FileStatus objects whose path names match
* and is accepted by the user-supplied path filter. Results are sorted by * {@code pathPattern} and is accepted by the user-supplied path filter.
* their path names. * Results are sorted by their path names.
* Return null if pathPattern has no glob and the path does not exist.
* Return an empty array if pathPattern has a glob and no path matches it.
* *
* @param pathPattern * @param pathPattern a regular expression specifying the path pattern
* a regular expression specifying the path pattern * @param filter a user-supplied path filter
* @param filter * @return null if {@code pathPattern} has no glob and the path does not exist
* a user-supplied path filter * an empty array if {@code pathPattern} has a glob and no path
* @return an array of FileStatus objects * matches it else an array of {@link FileStatus} objects matching the
* pattern
* @throws IOException if any I/O error occurs when fetching file status * @throws IOException if any I/O error occurs when fetching file status
*/ */
public FileStatus[] globStatus(Path pathPattern, PathFilter filter) public FileStatus[] globStatus(Path pathPattern, PathFilter filter)

View File

@ -40,8 +40,22 @@ class GlobExpander {
/** /**
* Expand globs in the given <code>filePattern</code> into a collection of * Expand globs in the given <code>filePattern</code> into a collection of
* file patterns so that in the expanded set no file pattern has a * file patterns so that in the expanded set no file pattern has a slash
* slash character ("/") in a curly bracket pair. * character ("/") in a curly bracket pair.
* <p>
* Some examples of how the filePattern is expanded:<br>
* <pre>
* <b>
* filePattern - Expanded file pattern </b>
* {a/b} - a/b
* /}{a/b} - /}a/b
* p{a/b,c/d}s - pa/bs, pc/ds
* {a/b,c/d,{e,f}} - a/b, c/d, {e,f}
* {a/b,c/d}{e,f} - a/b{e,f}, c/d{e,f}
* {a,b}/{b,{c/d,e/f}} - {a,b}/b, {a,b}/c/d, {a,b}/e/f
* {a,b}/{c/\d} - {a,b}/c/d
* </pre>
*
* @param filePattern * @param filePattern
* @return expanded file patterns * @return expanded file patterns
* @throws IOException * @throws IOException
@ -65,7 +79,7 @@ class GlobExpander {
/** /**
* Expand the leftmost outer curly bracket pair containing a * Expand the leftmost outer curly bracket pair containing a
* slash character ("/") in <code>filePattern</code>. * slash character ("/") in <code>filePattern</code>.
* @param filePattern * @param filePatternWithOffset
* @return expanded file patterns * @return expanded file patterns
* @throws IOException * @throws IOException
*/ */