Example usage for io.vertx.core.file AsyncFile close

List of usage examples for io.vertx.core.file AsyncFile close

Introduction

In this page you can find the example usage for io.vertx.core.file AsyncFile close.

Prototype

void close(Handler<AsyncResult<Void>> handler);

Source Link

Document

Close the file.

Usage

From source file:org.apache.servicecomb.foundation.vertx.http.ReadStreamPart.java

License:Apache License

protected void onFileOpened(File file, AsyncResult<AsyncFile> ar, CompletableFuture<File> future) {
    if (ar.failed()) {
        future.completeExceptionally(ar.cause());
        return;/*from  w  ww.j  av a  2s.c  om*/
    }

    AsyncFile asyncFile = ar.result();
    CompletableFuture<Void> saveFuture = saveToWriteStream(asyncFile);
    saveFuture.whenComplete((v, saveException) -> {
        asyncFile.close(closeAr -> {
            if (closeAr.failed()) {
                LOGGER.error("Failed to close file {}.", file);
            }

            // whatever close success or failed
            // will not affect to result
            // result just only related to write
            if (saveException == null) {
                future.complete(file);
                return;
            }

            future.completeExceptionally(saveException);
        });
    });
}

From source file:org.sfs.io.AsyncIO.java

License:Apache License

public static Observable<Void> close(AsyncFile asyncFile) {
    return Observable.defer(() -> {
        ObservableFuture<Void> rh = RxHelper.observableFuture();
        asyncFile.close(rh.toHandler());
        return rh;
    });// ww w .  j a  va2  s  .  c o m
}