/** * @return true if this file is pinned, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean needPin() throws IOException { return getUnCachedFileStatus().isPinned; }
/** * Returns the number of blocks the file has. * * @return the number of blocks * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public int getNumberOfBlocks() throws IOException { return getUnCachedFileStatus().getBlockIds().size(); }
/** * Returns whether this file is complete or not * * @return true if this file is complete, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean isCompleted() throws IOException { return getCachedFileStatus().isCompleted || getUnCachedFileStatus().isCompleted; }
/** * @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(); }
/** * 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(); }
/** * Return whether the file is in memory or not. Note that a file may be partly in memory. This * value is true only if the file is fully in memory. * * @return true if the file is fully in memory, false otherwise * @throws IOException if the underlying file does not exist or its metadata is corrupted */ public boolean isInMemory() throws IOException { return getUnCachedFileStatus().getInMemoryPercentage() == 100; }
/** * 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); } }
/** * @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()); }