/** * @return the file size in bytes * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public long length() throws IOException { return getUnCachedFileStatus().getLength(); }
/** * Creates a new file input stream. * * @param info the file information * @param options the client options */ public FileInStream(FileInfo info, InStreamOptions options) { mFileInfo = info; mBlockSize = info.getBlockSizeBytes(); mFileLength = info.getLength(); mContext = FileSystemContext.INSTANCE; mTachyonStorageType = options.getTachyonStorageType(); mShouldCacheCurrentBlock = mTachyonStorageType.isStore(); mClosed = false; }
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>()); } }
@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; }
TachyonFile fd = tachyonClient.open(path); FileInfo tFile = tachyonClient.getInfo(fd); long len = tFile.getLength(); String fileName = path.getName(); response.setContentType("application/octet-stream");
/** * 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; }
offset = relativeOffset; } else { offset = fileInfo.getLength() - relativeOffset; } else if (offset > fileInfo.getLength()) { offset = fileInfo.getLength(); UiFileInfo toAdd = new UiFileInfo(fileInfo); try { if (!toAdd.getIsDirectory() && fileInfo.getLength() > 0) { FileBlockInfo blockInfo = mMaster.getFileSystemMaster().getFileBlockInfoList(toAdd.getId()).get(0);
/** * 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; }
/** * 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; }