Java Code Examples for org.apache.hadoop.fs.Path#CUR_DIR

The following examples show how to use org.apache.hadoop.fs.Path#CUR_DIR . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hdfs-shell   File: ContextCommands.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized String getCurrentDir() {
    if (currentDir == null) {
        try {
            final Path path = new Path(Path.CUR_DIR);
            final FileSystem fs = getFileSystem();
            final FileStatus[] fileStatuses = fs.globStatus(path);
            if (fileStatuses == null || fileStatuses.length == 0) {
                return "";
            }
            homeDir = currentDir = fileStatuses[0].getPath().toUri().getPath();
        } catch (Exception e) {
            return "";
        }
    }
    return currentDir;
}
 
Example 2
Source Project: hadoop   File: CommandWithDestination.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  The last arg is expected to be a remote path, if only one argument is
 *  given then the destination will be the remote user's directory 
 *  @param args is the list of arguments
 *  @throws PathIOException if path doesn't exist or matches too many times 
 */
protected void getRemoteDestination(LinkedList<String> args)
throws IOException {
  if (args.size() < 2) {
    dst = new PathData(Path.CUR_DIR, getConf());
  } else {
    String pathString = args.removeLast();
    // if the path is a glob, then it must match one and only one path
    PathData[] items = PathData.expandAsGlob(pathString, getConf());
    switch (items.length) {
      case 0:
        throw new PathNotFoundException(pathString);
      case 1:
        dst = items[0];
        break;
      default:
        throw new PathIOException(pathString, "Too many matches");
    }
  }
}
 
Example 3
Source Project: hadoop   File: PathData.java    License: Apache License 2.0 6 votes vote down vote up
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) {
  String uriPath = srcUri.getPath();
  String cwdPath = cwdUri.getPath();
  if (cwdPath.equals(uriPath)) {
    return Path.CUR_DIR;
  }

  // find common ancestor
  int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir);
  
  StringBuilder relPath = new StringBuilder();    
  // take the remaining path fragment after the ancestor
  if (lastSep < uriPath.length()) {
    relPath.append(uriPath.substring(lastSep+1));
  }

  // if cwd has a path fragment after the ancestor, convert them to ".."
  if (lastSep < cwdPath.length()) {
    while (lastSep != -1) {
      if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR);
      relPath.insert(0, "..");
      lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1);
    }
  }
  return relPath.toString();
}
 
Example 4
Source Project: big-c   File: CommandWithDestination.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  The last arg is expected to be a remote path, if only one argument is
 *  given then the destination will be the remote user's directory 
 *  @param args is the list of arguments
 *  @throws PathIOException if path doesn't exist or matches too many times 
 */
protected void getRemoteDestination(LinkedList<String> args)
throws IOException {
  if (args.size() < 2) {
    dst = new PathData(Path.CUR_DIR, getConf());
  } else {
    String pathString = args.removeLast();
    // if the path is a glob, then it must match one and only one path
    PathData[] items = PathData.expandAsGlob(pathString, getConf());
    switch (items.length) {
      case 0:
        throw new PathNotFoundException(pathString);
      case 1:
        dst = items[0];
        break;
      default:
        throw new PathIOException(pathString, "Too many matches");
    }
  }
}
 
Example 5
Source Project: big-c   File: PathData.java    License: Apache License 2.0 6 votes vote down vote up
private static String relativize(URI cwdUri, URI srcUri, boolean isDir) {
  String uriPath = srcUri.getPath();
  String cwdPath = cwdUri.getPath();
  if (cwdPath.equals(uriPath)) {
    return Path.CUR_DIR;
  }

  // find common ancestor
  int lastSep = findLongestDirPrefix(cwdPath, uriPath, isDir);
  
  StringBuilder relPath = new StringBuilder();    
  // take the remaining path fragment after the ancestor
  if (lastSep < uriPath.length()) {
    relPath.append(uriPath.substring(lastSep+1));
  }

  // if cwd has a path fragment after the ancestor, convert them to ".."
  if (lastSep < cwdPath.length()) {
    while (lastSep != -1) {
      if (relPath.length() != 0) relPath.insert(0, Path.SEPARATOR);
      relPath.insert(0, "..");
      lastSep = cwdPath.indexOf(Path.SEPARATOR, lastSep+1);
    }
  }
  return relPath.toString();
}
 
Example 6
Source Project: hadoop   File: SnapshotDiffReport.java    License: Apache License 2.0 5 votes vote down vote up
static String getPathString(byte[] path) {
  String pathStr = DFSUtil.bytes2String(path);
  if (pathStr.isEmpty()) {
    return Path.CUR_DIR;
  } else {
    return Path.CUR_DIR + Path.SEPARATOR + pathStr;
  }
}
 
Example 7
Source Project: hadoop   File: CommandWithDestination.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *  The last arg is expected to be a local path, if only one argument is
 *  given then the destination will be the current directory 
 *  @param args is the list of arguments
 */
protected void getLocalDestination(LinkedList<String> args)
throws IOException {
  String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast();
  try {
    dst = new PathData(new URI(pathString), getConf());
  } catch (URISyntaxException e) {
    if (Path.WINDOWS) {
      // Unlike URI, PathData knows how to parse Windows drive-letter paths.
      dst = new PathData(pathString, getConf());
    } else {
      throw new IOException("unexpected URISyntaxException", e);
    }
  }
}
 
Example 8
Source Project: hadoop   File: TestPathData.java    License: Apache License 2.0 5 votes vote down vote up
@Test (timeout = 30000)
public void testCwdContents() throws Exception {
  String dirString = Path.CUR_DIR;
  PathData item = new PathData(dirString, conf);
  PathData[] items = item.getDirectoryContents();
  assertEquals(
      sortedString("d1", "d2"),
      sortedString(items)
  );
}
 
Example 9
Source Project: big-c   File: SnapshotDiffReport.java    License: Apache License 2.0 5 votes vote down vote up
static String getPathString(byte[] path) {
  String pathStr = DFSUtil.bytes2String(path);
  if (pathStr.isEmpty()) {
    return Path.CUR_DIR;
  } else {
    return Path.CUR_DIR + Path.SEPARATOR + pathStr;
  }
}
 
Example 10
Source Project: big-c   File: CommandWithDestination.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *  The last arg is expected to be a local path, if only one argument is
 *  given then the destination will be the current directory 
 *  @param args is the list of arguments
 */
protected void getLocalDestination(LinkedList<String> args)
throws IOException {
  String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast();
  try {
    dst = new PathData(new URI(pathString), getConf());
  } catch (URISyntaxException e) {
    if (Path.WINDOWS) {
      // Unlike URI, PathData knows how to parse Windows drive-letter paths.
      dst = new PathData(pathString, getConf());
    } else {
      throw new IOException("unexpected URISyntaxException", e);
    }
  }
}
 
Example 11
Source Project: big-c   File: TestPathData.java    License: Apache License 2.0 5 votes vote down vote up
@Test (timeout = 30000)
public void testCwdContents() throws Exception {
  String dirString = Path.CUR_DIR;
  PathData item = new PathData(dirString, conf);
  PathData[] items = item.getDirectoryContents();
  assertEquals(
      sortedString("d1", "d2"),
      sortedString(items)
  );
}