/** * Convenience method for {@link #getOutStream(TachyonURI, OutStreamOptions)} with default * options. */ public FileOutStream getOutStream(TachyonURI path) throws IOException, TachyonException, FileAlreadyExistsException, InvalidPathException { return getOutStream(path, OutStreamOptions.defaults()); }
private void writeFile(TachyonFileSystem tachyonClient) throws IOException, TachyonException { for (int i = 0; i < mNumFiles; i ++) { ByteBuffer buf = ByteBuffer.allocate(80); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < mNumFiles; k ++) { buf.putInt(k); } buf.flip(); TachyonURI filePath = new TachyonURI(mFileFolder + "/part-" + i); LOG.debug("Writing data to {}", filePath); OutputStream os = tachyonClient.getOutStream(filePath); os.write(buf.array()); os.close(); } }
private FileOutStream getOrCreate(TachyonFileSystem tachyonFileSystem, TachyonURI filePath, boolean deleteIfExists, OutStreamOptions clientOptions) throws IOException, TachyonException { TachyonFile file; try { file = tachyonFileSystem.open(filePath); } catch (Exception e) { file = null; } if (file == null) { // file doesn't exist yet, so create it return tachyonFileSystem.getOutStream(filePath, clientOptions); } else if (deleteIfExists) { // file exists, so delete it and recreate tachyonFileSystem.delete(file); return tachyonFileSystem.getOutStream(filePath, clientOptions); } // file exists and deleteIfExists is false throw new FileAlreadyExistsException(" file exists but deleteIfExists is false"); }
public void writePartition() throws IOException, TachyonException { if (sDebugMode) { mBuf.flip(); LOG.info(FormatUtils.byteBufferToString(mBuf)); } mBuf.flip(); for (int pId = mLeft; pId < mRight; pId ++) { final long startTimeMs = System.currentTimeMillis(); FileOutStream os = mTFS.getOutStream(new TachyonURI(sFileName + (pId + sBaseFileNumber))); for (int k = 0; k < sBlocksPerFile; k ++) { mBuf.putInt(0, k + mWorkerId); os.write(mBuf.array()); } os.close(); logPerIteration(startTimeMs, pId, "th WriteTachyonFile @ Worker ", pId); } }
/** * Creates a 0 byte file specified by argv. The file will be written to UnderFileSystem. * * @param path The TachyonURI path as the input of the command * @return 0 if command if successful, -1 if an error occurred * @throws IOException */ public int touch(TachyonURI path) throws IOException { try { mTfs.getOutStream(path, new OutStreamOptions.Builder(mTachyonConf) .setUnderStorageType(UnderStorageType.SYNC_PERSIST).build()).close(); } catch (TachyonException e) { throw new IOException(e.getMessage()); } System.out.println(path + " has been created"); return 0; }
/** * Gets the output stream for lineage job. If the file already exists on master, returns a dummy * output stream. */ @Override public FileOutStream getOutStream(TachyonURI path, OutStreamOptions options) throws IOException, TachyonException { long fileId; try { fileId = reinitializeFile(path, options); } catch (LineageDoesNotExistException e) { // not a lineage file return super.getOutStream(path, options); } if (fileId == -1) { return new DummyFileOutputStream(fileId, options); } return new LineageFileOutStream(fileId, options); } }
try { FileOutStream os = closer.register(tachyonClient.getOutStream(dstPath, OutStreamOptions.defaults())); FileInputStream in = closer.register(new FileInputStream(src)); FileChannel channel = closer.register(in.getChannel());
TachyonURI testURI = new TachyonURI(mWorkDir + mSuccessNum); if (ClientOpType.CREATE_FILE == mOpType) { sTfs.getOutStream(testURI, sOutStreamOptions).close(); } else if (ClientOpType.CREATE_DELETE_FILE == mOpType) { try { sTfs.getOutStream(testURI, sOutStreamOptions).close(); } catch (TachyonException e) { } else if (ClientOpType.CREATE_RENAME_FILE == mOpType) { try { sTfs.getOutStream(testURI, sOutStreamOptions).close(); } catch (TachyonException 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()); }
.setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType) .build(); FileOutStream os = tfs.getOutStream(fileURI, options);
/** * Creates a simple file with <code>len</code> bytes. * * @param tfs a TachyonFileSystem handler * @param fileName the name of the file to be created * @param tachyonStorageType TachyonStorageType used to create the file * @param underStorageType UnderStorageType used to create the file * @param len file size * @param blockCapacityByte block size of the file * @return the TachyonFile of the created file * @throws IOException if <code>path</code> is invalid (e.g., illegal URI) */ public static TachyonFile createByteFile(TachyonFileSystem tfs, String fileName, TachyonStorageType tachyonStorageType, UnderStorageType underStorageType, int len, long blockCapacityByte) throws IOException { try { OutStreamOptions options = new OutStreamOptions.Builder(ClientContext.getConf()) .setTachyonStorageType(tachyonStorageType).setUnderStorageType(underStorageType) .setBlockSizeBytes(blockCapacityByte).build(); FileOutStream os = tfs.getOutStream(new TachyonURI(fileName), options); for (int k = 0; k < len; k ++) { os.write((byte) k); } os.close(); return tfs.open(new TachyonURI(fileName)); } catch (TachyonException e) { throw new IOException(e.getMessage()); } }