/** * Convenience method for {@link #listStatus(TachyonFile, ListStatusOptions)} with default * options. */ public List<FileInfo> listStatus(TachyonFile file) throws IOException, TachyonException, FileDoesNotExistException { return listStatus(file, ListStatusOptions.defaults()); }
private List<FileInfo> listStatusSortedByIncreasingCreationTime(TachyonURI path) throws IOException { List<FileInfo> files = null; try { TachyonFile fd = mTfs.open(path); files = mTfs.listStatus(fd); } catch (TachyonException e) { throw new IOException(e.getMessage()); } Collections.sort(files, new Comparator<FileInfo>() { @Override public int compare(FileInfo fileInfo, FileInfo fileInfo2) { long t1 = fileInfo.creationTimeMs; long t2 = fileInfo2.creationTimeMs; if (t1 < t2) { return -1; } if (t1 == t2) { return 0; } return 1; } }); return files; }
/** * Returns a list of files at a given <code>path</code>. * * @param tfs a TachyonFileSystem handler * @param path a path in tachyon file system * @return a list of strings representing the file names under the given path * @throws IOException if <code>path</code> does not exist or is invalid */ public static List<String> listFiles(TachyonFileSystem tfs, String path) throws IOException { try { TachyonFile file = tfs.open(new TachyonURI(path)); if (file == null) { throw new IOException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } List<FileInfo> infos = tfs.listStatus(file); List<String> res = new ArrayList<String>(); for (FileInfo info : infos) { res.add(info.getPath()); if (info.isFolder) { res.addAll(listFiles(tfs, info.getPath())); } } return res; } catch (TachyonException e) { throw new IOException(e.getMessage()); } }
List<FileInfo> files = null; try { files = mTfs.listStatus(srcFd); } catch (TachyonException e) { System.out.println(srcFd + " does not exist.");
private long[] countHelper(TachyonURI path) throws IOException { TachyonFile fd; FileInfo fInfo; try { fd = mTfs.open(path); fInfo = mTfs.getInfo(fd); } catch (TachyonException e) { throw new IOException(e.getMessage()); } if (!fInfo.isFolder) { return new long[] {1L, 0L, fInfo.length}; } long[] rtn = new long[] {0L, 1L, 0L}; List<FileInfo> files = null; try { files = mTfs.listStatus(fd); } catch (TachyonException e) { throw new IOException(e.getMessage()); } Collections.sort(files); for (FileInfo file : files) { long[] toAdd = countHelper(new TachyonURI(file.getPath())); rtn[0] += toAdd[0]; rtn[1] += toAdd[1]; rtn[2] += toAdd[2]; } return rtn; }
/** * Calculates the size of a path (file or folder) specified by a TachyonURI. * * @param tachyonFS A TachyonFileSystem * @param path A TachyonURI denoting the path * @return total size of the specified path in byte * @throws IOException */ private long getFileOrFolderSize(TachyonFileSystem tachyonFS, TachyonURI path) throws IOException { long sizeInBytes = 0; List<FileInfo> files; try { TachyonFile inputFile = tachyonFS.open(path); files = tachyonFS.listStatus(inputFile); } catch (TachyonException e) { throw new IOException(e.getMessage()); } for (FileInfo file : files) { if (file.isFolder) { TachyonURI subFolder = new TachyonURI(file.getPath()); sizeInBytes += getFileOrFolderSize(tachyonFS, subFolder); } else { sizeInBytes += file.getLength(); } } return sizeInBytes; }
List<FileInfo> files = tachyonClient.listStatus(fd); Collections.sort(files); for (FileInfo file : files) {
try { TachyonFile parentFile = tachyonClient.open(parentDir); files = tachyonClient.listStatus(parentFile); } catch (TachyonException e) { throw new IOException(e);