/** * Convenience method for {@link #getInStream(TachyonFile, InStreamOptions)} with default options. */ public FileInStream getInStream(TachyonFile file) throws IOException, TachyonException, FileDoesNotExistException { return getInStream(file, InStreamOptions.defaults()); }
private boolean readFile(TachyonFileSystem tachyonFileSystem, long fileId) throws IOException, TachyonException { boolean pass = true; LOG.debug("Reading data..."); TachyonFile file = new TachyonFile(fileId); final long startTimeMs = CommonUtils.getCurrentMs(); FileInStream is = tachyonFileSystem.getInStream(file, mReadOptions); ByteBuffer buf = ByteBuffer.allocate((int) is.remaining()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < mNumbers; k ++) { pass = pass && (buf.getInt() == k); } is.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; }
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; }
private boolean read(TachyonFileSystem tachyonFileSystem, TachyonURI filePath, ReadType readType) throws IOException, TachyonException { InStreamOptions clientOptions = new InStreamOptions.Builder(ClientContext.getConf()) .setReadType(readType).build(); TachyonFile file = tachyonFileSystem.open(filePath); DataInputStream input = new DataInputStream(tachyonFileSystem.getInStream(file, clientOptions)); boolean passes = true; try { int length = input.readInt(); for (int i = 0; i < length; i ++) { passes &= (input.readInt() == i); } } finally { input.close(); } return passes; }
InputStream is = mTFS.getInStream(file); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); final long startTimeMs = System.currentTimeMillis(); TachyonFile file = mTFS.open(new TachyonURI(sFileName + (pId + sBaseFileNumber))); InputStream is = mTFS.getInStream(file); long len = sBlocksPerFile * sBlockSizeBytes; final long startTimeMs = System.currentTimeMillis(); TachyonFile file = mTFS.open(new TachyonURI(sFileName + (pId + sBaseFileNumber))); InputStream is = mTFS.getInStream(file); for (int i = 0; i < sBlocksPerFile; i ++) { is.read(mBuf.array());
InStreamOptions op = new InStreamOptions.Builder(mTachyonConf) .setTachyonStorageType(TachyonStorageType.NO_STORE).build(); FileInStream is = closer.register(mTfs.getInStream(srcFd, op)); FileOutputStream out = closer.register(new FileOutputStream(dstFile)); byte[] buf = new byte[64 * Constants.MB];
is = tachyonClient.getInStream(fd, op); out = response.getOutputStream(); ByteStreams.copy(is, out);
/** * 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); } }
FileInStream is; try { is = mTfs.getInStream(fd, op); } catch (TachyonException e) { System.out.print(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
InStreamOptions op = new InStreamOptions.Builder(mTachyonConf) .setTachyonStorageType(TachyonStorageType.STORE).build(); FileInStream in = closer.register(mTfs.getInStream(fd, op)); byte[] buf = new byte[8 * Constants.MB]; while (in.read(buf) != -1) {
InStreamOptions readNoCache = new InStreamOptions.Builder(mTachyonConf) .setTachyonStorageType(TachyonStorageType.NO_STORE).build(); FileInStream is = tFS.getInStream(tFile, readNoCache); try { int len = (int) Math.min(5 * Constants.KB, fileInfo.length - offset);
FileInStream is = null; try { is = mTfs.getInStream(fd, op); byte[] buf = new byte[Constants.KB]; long bytesToRead = 0L;