use of io.vertx.core.file.FileSystem in project vertx-web by vert-x3.
the class StaticHandlerImpl method isFileExisting.
private synchronized void isFileExisting(RoutingContext context, String file, Handler<AsyncResult<Boolean>> resultHandler) {
FileSystem fs = context.vertx().fileSystem();
wrapInTCCLSwitch(() -> fs.exists(file, resultHandler));
}
use of io.vertx.core.file.FileSystem in project georocket by georocket.
the class FileStore method getOne.
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
String absolutePath = Paths.get(root, path).toString();
// check if chunk exists
FileSystem fs = vertx.fileSystem();
ObservableFuture<Boolean> observable = RxHelper.observableFuture();
fs.exists(absolutePath, observable.toHandler());
observable.flatMap(exists -> {
if (!exists) {
return Observable.error(new FileNotFoundException("Could not find chunk: " + path));
}
return Observable.just(exists);
}).flatMap(exists -> {
// get chunk's size
ObservableFuture<FileProps> propsObservable = RxHelper.observableFuture();
fs.props(absolutePath, propsObservable.toHandler());
return propsObservable;
}).map(props -> props.size()).flatMap(size -> {
// open chunk
ObservableFuture<AsyncFile> openObservable = RxHelper.observableFuture();
OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false);
fs.open(absolutePath, openOptions, openObservable.toHandler());
return openObservable.map(f -> new FileChunkReadStream(size, f));
}).subscribe(readStream -> {
// send chunk to peer
handler.handle(Future.succeededFuture(readStream));
}, err -> {
handler.handle(Future.failedFuture(err));
});
}
use of io.vertx.core.file.FileSystem in project georocket by georocket.
the class FileStore method doDeleteChunks.
@Override
protected void doDeleteChunks(Queue<String> paths, Handler<AsyncResult<Void>> handler) {
if (paths.isEmpty()) {
handler.handle(Future.succeededFuture());
return;
}
String path = paths.poll();
FileSystem fs = vertx.fileSystem();
String absolutePath = Paths.get(root, path).toString();
fs.exists(absolutePath, existAr -> {
if (existAr.failed()) {
handler.handle(Future.failedFuture(existAr.cause()));
} else {
if (existAr.result()) {
fs.delete(absolutePath, deleteAr -> {
if (deleteAr.failed()) {
handler.handle(Future.failedFuture(deleteAr.cause()));
} else {
doDeleteChunks(paths, handler);
}
});
} else {
doDeleteChunks(paths, handler);
}
}
});
}
use of io.vertx.core.file.FileSystem in project vertx-zero by silentbalanceyh.
the class FileResolver method resolve.
@Override
public Epsilon<T> resolve(final RoutingContext context, final Epsilon<T> income) {
final Set<FileUpload> fileUploads = context.fileUploads();
if (Values.ONE == fileUploads.size()) {
final FileUpload fileUpload = fileUploads.iterator().next();
// Returned directly reference for FileUpload
if (income.getArgType().isAssignableFrom(FileUpload.class)) {
income.setValue((T) fileUpload);
} else if (income.getArgType() == File.class) {
// File object construction
final Object ret = ZeroSerializer.getValue(income.getArgType(), fileUpload.uploadedFileName());
income.setValue((T) ret);
} else if (income.getArgType().isArray()) {
// byte[]
if (byte.class == income.getArgType().getComponentType() || Byte.class == income.getArgType().getComponentType()) {
final FileSystem fileSystem = context.vertx().fileSystem();
final Buffer buffer = fileSystem.readFileBlocking(fileUpload.uploadedFileName());
income.setValue((T) buffer.getBytes());
}
} else if (Buffer.class.isAssignableFrom(income.getArgType())) {
// Buffer
final FileSystem fileSystem = context.vertx().fileSystem();
final Buffer buffer = fileSystem.readFileBlocking(fileUpload.uploadedFileName());
income.setValue((T) buffer);
}
} else {
// Multi Files only support Set<FileUpload>
income.setValue((T) fileUploads);
}
return income;
}
use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class CoreExamples method exampleFutureComposition1.
public void exampleFutureComposition1(Vertx vertx) {
FileSystem fs = vertx.fileSystem();
Future<Void> future = fs.createFile("/foo").compose(v -> {
// When the file is created (fut1), execute this:
return fs.writeFile("/foo", Buffer.buffer());
}).compose(v -> {
// When the file is written (fut2), execute this:
return fs.move("/foo", "/bar");
});
}
Aggregations