/** * @return true if this is a file, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean isFile() throws IOException { return !isDirectory(); }
/** * {@inheritDoc} * * If the file does not exist in Tachyon, query it from HDFS. */ @Override public FileStatus getFileStatus(Path path) throws IOException { TachyonURI tPath = new TachyonURI(Utils.getPathWithoutScheme(path)); Path hdfsPath = Utils.getHDFSPath(tPath, mUnderFSAddress); LOG.info("getFileStatus(" + path + "): HDFS Path: " + hdfsPath + " TPath: " + mTachyonHeader + tPath); if (mStatistics != null) { mStatistics.incrementReadOps(1); } TachyonFile file; try { file = mTFS.getFile(tPath); } catch (IOException ioe) { LOG.info("File does not exist: " + path); throw new FileNotFoundException("File does not exist: " + path); } FileStatus ret = new FileStatus(file.length(), file.isDirectory(), file.getDiskReplication(), file.getBlockSizeByte(), file.getCreationTimeMs(), file.getCreationTimeMs(), null, null, null, new Path(mTachyonHeader + tPath)); return ret; }
/** * 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); } }