hadoop (1.0.4) Path 详解

Path    对路径进行解析,将参数转换为标准的URI格式,对Path的参数作判断,标准化,字符化等操作。为了便于理解Path,

各位可以先参看URI的详解,链接http://www.cnblogs.com/springside5/archive/2012/05/06/2486245.html



import java.net.*;
import java.io.*;

import org.apache.hadoop.conf.Configuration;

/** Names a file or directory in a {@link FileSystem}.
 * Path strings use slash as the directory separator.  A path string is
 * absolute if it begins with a slash.
 */
public class Path implements Comparable {

  /** The directory separator, a slash. */
  public static final String SEPARATOR = "/";
  public static final char SEPARATOR_CHAR = '/';
 
  public static final String CUR_DIR = ".";
 
  static final boolean WINDOWS
    = System.getProperty("os.name").startsWith("Windows");

 private URI uri;                                // a hierarchical uri      //定义了Path类中的私有变量uri,路径以uri的格式表示,其后对Path的操作也主要通过对uri的操作实现。

  /** Resolve a child path against a parent path. */
  public Path(String parent, String child) {                                // 构造函数,我们可以发现其最终转换为Path(Path,Path)的构造函数。
    this(new Path(parent), new Path(child));
  }

  /** Resolve a child path against a parent path. */
  public Path(Path parent, String child) {
    this(parent, new Path(child));
  }

  /** Resolve a child path against a parent path. */
  public Path(String parent, Path child) {
    this(new Path(parent), child);
  }

  /** Resolve a child path against a parent path. */
  public Path(Path parent, Path child) {                                               //对parent和child做规范化处理
    // Add a slash to parent's path so resolution is compatible with URI's
    URI parentUri = parent.uri;
    String parentPath = parentUri.getPath();
    if (!(parentPath.equals("/") || parentPath.equals("")))                  //重新构造parentUri,在路径的结尾添加一个“/”,让parentUri与URI兼容

      try {
        parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(),
                      parentUri.getPath()+"/", null, parentUri.getFragment());
      } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
      }
    URI resolved = parentUri.resolve(child.uri);
    initialize(resolved.getScheme(), resolved.getAuthority(),
               normalizePath(resolved.getPath()),

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值