/** * Convenience method for {@link TachyonFileSystemCore#getInfo(TachyonFile, GetInfoOptions)} with * default options. */ public FileInfo getInfo(TachyonFile file) throws FileDoesNotExistException, IOException, TachyonException { return getInfo(file, GetInfoOptions.defaults()); }
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; }
/** * Gets a {@link FileInStream} for the specified file. The stream's settings can be customized by * setting the options parameter. The caller should close the stream after finishing the * operations on it. * * @param file the handler for the file to read * @param options the set of options specific to this operation * @return an input stream to read the file * @throws IOException if a non-Tachyon exception occurs * @throws TachyonException if an unexpected Tachyon exception is thrown * @throws FileDoesNotExistException if the given file does not exist */ public FileInStream getInStream(TachyonFile file, InStreamOptions options) throws IOException, TachyonException, FileDoesNotExistException { FileInfo info = getInfo(file, GetInfoOptions.defaults()); Preconditions.checkState(!info.isIsFolder(), "Cannot read from a folder"); return new FileInStream(info, options); }
/** * Removes the file specified by 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 rm(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) { System.out.println("rm: cannot remove a directory, please try rmr <path>"); return -1; } try { mTfs.delete(fd); System.out.println(path + " has been removed"); return 0; } catch (IOException ioe) { return -1; } catch (TachyonException e) { throw new IOException(e.getMessage()); } }
/** * Displays the file's all blocks info * * @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 fileinfo(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) { System.out.println(path + " is a directory path so does not have file blocks."); return -1; } System.out.println(path + " with file id " + fd.getFileId() + " has the following blocks: "); for (long blockId : fInfo.getBlockIds()) { System.out.println(TachyonBlockStore.get().getInfo(blockId)); } return 0; }
TachyonFile fd = tachyonClient.openIfExists(dstPath); if (fd != null) { FileInfo tFile = tachyonClient.getInfo(fd); if (tFile.isFolder) { dstPath = dstPath.join(src.getName());
try { srcFd = mTfs.open(srcPath); srcFileInfo = mTfs.getInfo(srcFd); } catch (TachyonException e) { throw new IOException(e.getMessage());
TachyonFileSystem tachyonClient = TachyonFileSystemFactory.get(); TachyonFile fd = tachyonClient.open(path); FileInfo tFile = tachyonClient.getInfo(fd); long len = tFile.getLength(); String fileName = path.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; }
try { TachyonFile dstFd = mTfs.open(dstPath); dstFileInfo = mTfs.getInfo(dstFd); } catch (TachyonException e) { throw new IOException(e.getMessage());
/** * Displays a list of hosts that have the file specified in argv stored. * * @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 location(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()); } System.out.println(path + " with file id " + fd.getFileId() + " is on nodes: "); for (long blockId : fInfo.getBlockIds()) { for (BlockLocation location : TachyonBlockStore.get().getInfo(blockId).getLocations()) { System.out.println(location.getWorkerAddress().getHost()); } } return 0; }
try { fd = mTfs.open(path); tFile = mTfs.getInfo(fd); } catch (TachyonException e) { throw new IOException(e.getMessage());
try { fd = mTfs.open(filePath); fInfo = mTfs.getInfo(fd); } catch (IOException ioe) { return -1;
try { fd = mTfs.open(path); fInfo = mTfs.getInfo(fd); } catch (TachyonException e) { throw new IOException(e.getMessage());
TachyonFile tFile = tFS.open(path); String fileData = null; FileInfo fileInfo = tFS.getInfo(tFile); if (fileInfo.isCompleted) { InStreamOptions readNoCache = new InStreamOptions.Builder(mTachyonConf)
fileInfo = tachyonFileSystem.getInfo(file); if (fileInfo == null) { throw new FileDoesNotExistException(