/** * Returns the block size of this file. * * @return the block size in bytes * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public long getBlockSizeByte() throws IOException { return getCachedFileStatus().getBlockSizeBytes(); }
private boolean readFile(TachyonFileSystem tachyonClient) throws IOException, TachyonException { boolean pass = true; for (int i = 0; i < mNumFiles; i ++) { TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); LOG.debug("Reading data from {}", filePath); TachyonFile file = tachyonClient.open(filePath); FileInStream is = tachyonClient.getInStream(file); FileInfo info = tachyonClient.getInfo(file); ByteBuffer buf = ByteBuffer.allocate((int) info.getBlockSizeBytes()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < mNumFiles; k ++) { pass = pass && (buf.getInt() == k); } is.close(); } return pass; }
/** * 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; }
/** * @return the {@code OutStream} of this file * @throws IOException when an event that prevents the operation from completing is encountered */ public FileOutStream getOutStream() throws IOException { if (isCompleted()) { throw new IOException("Overriding after completion not supported."); } WriteType writeType = mTachyonConf.getEnum(Constants.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class); FileInfo info = getUnCachedFileStatus(); OutStreamOptions.Builder optionsBuilder = new OutStreamOptions.Builder(mTachyonConf); optionsBuilder.setBlockSizeBytes(info.getBlockSizeBytes()) .setTachyonStorageType(writeType.getTachyonStorageType()) .setUnderStorageType(writeType.getUnderStorageType()); return mTFS.getOutStream(mFileId, optionsBuilder.build()); }