/** * Creates a new file in the file system. * * @param path The path of the file * @param ufsPath The path of the file in the under file system. If this is empty, the file does * not exist in the under file system yet. * @param blockSizeBytes The size of the block in bytes. It is -1 iff ufsPath is non-empty. * @param recursive Creates necessary parent folders if true, not otherwise. * @return The file id, which is globally unique * @throws IOException if the underlying master RPC fails */ @Override public synchronized long createFile(TachyonURI path, TachyonURI ufsPath, long blockSizeBytes, boolean recursive) throws IOException { validateUri(path); try { if (blockSizeBytes > 0) { CreateOptions options = new CreateOptions.Builder(ClientContext.getConf()).setBlockSizeBytes(blockSizeBytes) .setRecursive(recursive).build(); return mFSMasterClient.create(path.getPath(), options); } else { return mFSMasterClient.loadMetadata(path.getPath(), recursive); } } catch (TachyonException e) { throw new IOException(e); } }
@Override public TachyonFile create(TachyonURI path, CreateOptions options) throws FileAlreadyExistsException, IOException, InvalidPathException, TachyonException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); try { final long fileId = masterClient.create(path.getPath(), options); return new TachyonFile(fileId); } catch (TachyonException e) { if (e.getType() == TachyonExceptionType.BLOCK_INFO) { throw new FileAlreadyExistsException(e.getMessage(), e); } else { TachyonException.unwrap(e, FileAlreadyExistsException.class); TachyonException.unwrap(e, InvalidPathException.class); throw e; } } finally { mContext.releaseMasterClient(masterClient); } }