@Override public Flowable<Buffer> read(String binaryUuid) { String path = getFilePath(binaryUuid); Flowable<Buffer> obs = FileSystem.newInstance(Mesh.vertx().fileSystem()) .rxOpen(path, new OpenOptions()) .toFlowable() .flatMap(RxUtil::toBufferFlow); return obs; }
/** * Opens a file and reads its properties. * * @param path * Path to the file * @return */ public static Single<PropReadFileStream> openFile(Vertx vertx, String path) { FileSystem fs = vertx.fileSystem(); return Single.zip(fs.rxProps(path).map(props -> props.getDelegate()), fs.rxOpen(path, openOptions).map(file -> file.getDelegate()), (props, file) -> { return new PropReadFileStream(props, file, path); }); }
@Override public Completable store(Flowable<Buffer> stream, String uuid) { return Completable.defer(() -> { FileSystem fileSystem = FileSystem.newInstance(Mesh.vertx().fileSystem()); String path = getFilePath(uuid); log.debug("Saving data for field to path {" + path + "}"); MeshUploadOptions uploadOptions = Mesh.mesh().getOptions().getUploadOptions(); File uploadFolder = new File(uploadOptions.getDirectory(), getSegmentedPath(uuid)); if (!uploadFolder.exists()) { if (!uploadFolder.mkdirs()) { log.error("Failed to create target folder {" + uploadFolder.getAbsolutePath() + "}"); throw error(BAD_REQUEST, "node_error_upload_failed"); } if (log.isDebugEnabled()) { log.debug("Created folder {" + uploadFolder.getAbsolutePath() + "}"); } } File targetFile = new File(uploadFolder, uuid + ".bin"); return fileSystem.rxOpen(targetFile.getAbsolutePath(), new OpenOptions()).flatMapCompletable(file -> stream .map(io.vertx.reactivex.core.buffer.Buffer::new) .doOnNext(file::write) .ignoreElements() .andThen(file.rxFlush()) .andThen(file.rxClose()) .doOnError(err -> file.close()) ); }); }