public static String absolutePath(Path p) { if (p == null) return ""; StringBuilder sb = new StringBuilder(); Path parentPath = p.getParent(); if (parentPath == null) return "/"; sb.append(absolutePath(parentPath)); if (sb.length() > 1) sb.append("/"); sb.append(p.getName()); return sb.toString(); }
/** * open a file for writing * * @param hdfsPath !null path - * @return !null stream */ @Override public OutputStream openFileForWrite(final Path src) { if (isRunningAsUser()) { return super.openFileForWrite(src); } if (true) throw new UnsupportedOperationException("Fix This"); // ToDo final FileSystem fs = getDFS(); try { Path parent = src.getParent(); guaranteeDirectory(parent); return FileSystem.create(fs, src, FULL_FILE_ACCESS); } catch (IOException e) { throw new RuntimeException(e); } }
/** * open a file for reading * * @param hdfsPath !null path - probably of an existing file * @return !null stream */ @Override public InputStream openFileForRead(Path src) { if (isRunningAsUser()) { return super.openFileForRead(src); } String hdfsPath = src.toString(); if (isFileNameLocal(hdfsPath)) { try { return new FileInputStream(hdfsPath); // better be local } catch (FileNotFoundException e) { throw new RuntimeException(e); } } if (true) throw new UnsupportedOperationException("Fix This"); // ToDo final FileSystem fs = getDFS(); try { return fs.open(src); } catch (IOException e) { throw new RuntimeException(e); } }