/** * Returns the path of this file in the Tachyon file system. * * @return the path * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public String getPath() throws IOException { return getUnCachedFileStatus().getPath(); }
throw new IOException(e); path = info.getPath();
/** * 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()); } }
public UiFileInfo(FileInfo fileInfo) { mId = fileInfo.getFileId(); mName = fileInfo.getName(); mAbsolutePath = fileInfo.getPath(); mBlockSizeBytes = fileInfo.getBlockSizeBytes(); mSize = fileInfo.getLength(); mCreationTimeMs = fileInfo.getCreationTimeMs(); mLastModificationTimeMs = fileInfo.getLastModificationTimeMs(); mInMemory = (100 == fileInfo.inMemoryPercentage); mInMemoryPercent = fileInfo.getInMemoryPercentage(); mIsDirectory = fileInfo.isFolder; mIsPinned = fileInfo.isPinned; mFileLocations = new ArrayList<String>(); for (int i = 0; i < StorageLevelAlias.SIZE; i ++) { mBlocksOnTier.add(new ArrayList<UiBlockInfo>()); } }
throw new FileDoesNotExistException(currentPath.toString()); downloadFile(new TachyonURI(fileInfo.getPath()), request, response); } catch (FileDoesNotExistException e) { request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getMessage());
@Override public FileStatus[] listStatus(Path path) throws IOException { TachyonURI tPath = new TachyonURI(Utils.getPathWithoutScheme(path)); Path hdfsPath = Utils.getHDFSPath(tPath, mUnderFSAddress); LOG.info("listStatus(" + path + "): HDFS Path: " + hdfsPath); if (mStatistics != null) { mStatistics.incrementReadOps(1); } if (!mTFS.exist(tPath)) { throw new FileNotFoundException("File does not exist: " + path); } List<FileInfo> files = mTFS.listStatus(tPath); FileStatus[] ret = new FileStatus[files.size()]; for (int k = 0; k < files.size(); k ++) { FileInfo info = files.get(k); // TODO(hy): Replicate 3 with the number of disk replications. ret[k] = new FileStatus(info.getLength(), info.isFolder, 3, info.getBlockSizeBytes(), info.getCreationTimeMs(), info.getCreationTimeMs(), null, null, null, new Path( mTachyonHeader + info.getPath())); } return ret; }
copyToLocal(new TachyonURI(srcPath.getScheme(), srcPath.getAuthority(), file.getPath()), new File(dstFile.getAbsolutePath(), file.getName()));
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; }
/** * Displays information for all directories and files directly under the path specified in argv. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int ls(TachyonURI path) throws IOException { List<FileInfo> files = listStatusSortedByIncreasingCreationTime(path); String format = "%-10s%-25s%-15s%-5s%n"; for (FileInfo file : files) { String inMemory = ""; if (!file.isFolder) { if (100 == file.inMemoryPercentage) { inMemory = "In Memory"; } else { inMemory = "Not In Memory"; } } System.out.format(format, FormatUtils.getSizeFromBytes(file.getLength()), convertMsToDate(file.getCreationTimeMs()), inMemory, file.getPath()); } return 0; }
FileInfo fileInfo; fileInfo = mBlockDataManager.getFileInfo(fileId); TachyonURI uri = new TachyonURI(fileInfo.getPath()); String dstPath = PathUtils.concatPath(ufsRoot, fileInfo.getPath()); LOG.info("persist file " + fileId + " at " + dstPath); String parentPath = PathUtils.concatPath(ufsRoot, uri.getParent().getPath());
/** * Displays information for all directories and files under the path specified in argv * recursively. * * @param path The TachyonURI path as the input of the command * @return 0 if command is successful, -1 if an error occurred * @throws IOException */ public int lsr(TachyonURI path) throws IOException { List<FileInfo> files = listStatusSortedByIncreasingCreationTime(path); String format = "%-10s%-25s%-15s%-5s%n"; for (FileInfo file : files) { String inMemory = ""; if (!file.isFolder) { if (100 == file.inMemoryPercentage) { inMemory = "In Memory"; } else { inMemory = "Not In Memory"; } } System.out.format(format, FormatUtils.getSizeFromBytes(file.getLength()), convertMsToDate(file.getCreationTimeMs()), inMemory, file.getPath()); if (file.isFolder) { lsr(new TachyonURI(path.getScheme(), path.getAuthority(), file.getPath())); } } return 0; }
/** * Return the {@code InStream} of this file based on the specified read type. If it has no block, * return an {@code EmptyBlockInStream}; if it has only one block, return a {@code BlockInStream} * of the block; otherwise return a {@code FileInStream}. * * @param readType the InStream's read type * @return the <code>InStream</code> * @throws IOException when an event that prevents the operation from completing is encountered */ public FileInStream getInStream(ReadType readType) throws IOException { if (readType == null) { throw new IOException("ReadType can not be null."); } if (!isCompleted()) { throw new IOException("The file " + this + " is not complete."); } if (isDirectory()) { throw new IOException("Cannot open a directory for reading."); } FileInfo info = getUnCachedFileStatus(); TachyonURI uri = new TachyonURI(info.getPath()); InStreamOptions.Builder optionsBuilder = new InStreamOptions.Builder(mTachyonConf); optionsBuilder.setTachyonStorageType(readType.getTachyonStorageType()); try { tachyon.client.file.TachyonFile newFile = mTFS.open(uri); return mTFS.getInStream(newFile, optionsBuilder.build()); } catch (TachyonException e) { throw new IOException(e); } }
/** * 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; }
new TachyonURI(inputURI.getScheme(), inputURI.getAuthority(), file.getPath()); if (match(fileURI, inputURI)) { // if it matches res.add(fileURI); if (file.isFolder) { // if it is a folder, we do it recursively TachyonURI dirURI = new TachyonURI(inputURI.getScheme(), inputURI.getAuthority(), file.getPath()); String prefix = inputURI.getLeadingPath(dirURI.getDepth()); if (prefix != null && match(dirURI, new TachyonURI(prefix))) {
Collections.sort(files); for (FileInfo file : files) { TachyonURI newPath = new TachyonURI(file.getPath()); if (loadPath(tachyonClient, newPath) == -1) { return -1;
ret.id = fileInfo.getFileId(); ret.name = fileInfo.getName(); ret.path = fileInfo.getPath(); ret.columns = mRawTables.getColumns(ret.id); ret.metadata = mRawTables.getMetadata(ret.id);