List of usage examples for org.apache.hadoop.fs Path Path
public Path(URI aUri)
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public boolean exists(String path) throws IOException { IOException te = null;//from w w w .ja v a 2s . co m RetryPolicy retryPolicy = new CountingRetry(MAX_TRY); while (retryPolicy.attemptRetry()) { try { return mFileSystem.exists(new Path(path)); } catch (IOException e) { LOG.error("{} try to check if {} exists : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e); te = e; } } throw te; }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public long getBlockSizeByte(String path) throws IOException { Path tPath = new Path(path); if (!mFileSystem.exists(tPath)) { throw new FileNotFoundException(path); }//from w ww. jav a 2s. co m FileStatus fs = mFileSystem.getFileStatus(tPath); return fs.getBlockSize(); }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public List<String> getFileLocations(String path, long offset) throws IOException { List<String> ret = new ArrayList<>(); try {//from ww w . ja v a 2s .com FileStatus fStatus = mFileSystem.getFileStatus(new Path(path)); BlockLocation[] bLocations = mFileSystem.getFileBlockLocations(fStatus, offset, 1); if (bLocations.length > 0) { String[] names = bLocations[0].getNames(); Collections.addAll(ret, names); } } catch (IOException e) { LOG.error("Unable to get file location for {}", path, e); } return ret; }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public long getFileSize(String path) throws IOException { Path tPath = new Path(path); RetryPolicy retryPolicy = new CountingRetry(MAX_TRY); while (retryPolicy.attemptRetry()) { try {/*w w w.java 2s .com*/ FileStatus fs = mFileSystem.getFileStatus(tPath); return fs.getLen(); } catch (IOException e) { LOG.error("{} try to get file size for {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e); } } return -1; }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public long getModificationTimeMs(String path) throws IOException { Path tPath = new Path(path); if (!mFileSystem.exists(tPath)) { throw new FileNotFoundException(path); }/*w w w .j ava 2 s . c om*/ FileStatus fs = mFileSystem.getFileStatus(tPath); return fs.getModificationTime(); }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public boolean isFile(String path) throws IOException { return mFileSystem.isFile(new Path(path)); }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public String[] list(String path) throws IOException { FileStatus[] files;//from w w w. ja v a 2 s. co m try { files = mFileSystem.listStatus(new Path(path)); } catch (FileNotFoundException e) { return null; } if (files != null && !isFile(path)) { String[] rtn = new String[files.length]; int i = 0; for (FileStatus status : files) { // only return the relative path, to keep consistent with java.io.File.list() rtn[i++] = status.getPath().getName(); } return rtn; } else { return null; } }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public boolean mkdirs(String path, MkdirsOptions options) throws IOException { IOException te = null;/*w w w . j a v a2 s . c o m*/ RetryPolicy retryPolicy = new CountingRetry(MAX_TRY); while (retryPolicy.attemptRetry()) { try { Path hdfsPath = new Path(path); if (mFileSystem.exists(hdfsPath)) { LOG.debug("Trying to create existing directory at {}", path); return false; } // Create directories one by one with explicit permissions to ensure no umask is applied, // using mkdirs will apply the permission only to the last directory Stack<Path> dirsToMake = new Stack<>(); dirsToMake.push(hdfsPath); Path parent = hdfsPath.getParent(); while (!mFileSystem.exists(parent)) { dirsToMake.push(parent); parent = parent.getParent(); } while (!dirsToMake.empty()) { if (!FileSystem.mkdirs(mFileSystem, dirsToMake.pop(), new FsPermission(options.getPermission().getMode().toShort()))) { return false; } } return true; } catch (IOException e) { LOG.error("{} try to make directory for {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e); te = e; } } throw te; }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public FSDataInputStream open(String path) throws IOException { IOException te = null;//from w ww . j ava 2 s . co m RetryPolicy retryPolicy = new CountingRetry(MAX_TRY); while (retryPolicy.attemptRetry()) { try { return mFileSystem.open(new Path(path)); } catch (IOException e) { LOG.error("{} try to open {} : {}", retryPolicy.getRetryCount(), path, e.getMessage(), e); te = e; } } throw te; }
From source file:alluxio.underfs.hdfs.HdfsUnderFileSystem.java
License:Apache License
@Override public boolean rename(String src, String dst) throws IOException { LOG.debug("Renaming from {} to {}", src, dst); if (!exists(src)) { LOG.error("File {} does not exist. Therefore rename to {} failed.", src, dst); return false; }//from www . j a v a2 s.c om if (exists(dst)) { LOG.error("File {} does exist. Therefore rename from {} failed.", dst, src); return false; } IOException te = null; RetryPolicy retryPolicy = new CountingRetry(MAX_TRY); while (retryPolicy.attemptRetry()) { try { return mFileSystem.rename(new Path(src), new Path(dst)); } catch (IOException e) { LOG.error("{} try to rename {} to {} : {}", retryPolicy.getRetryCount(), src, dst, e.getMessage(), e); te = e; } } throw te; }