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

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

Introduction

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

Prototype

@Override
    AsyncFile endHandler(Handler<Void> endHandler);

Source Link

Usage

From source file:examples.FileSystemExamples.java

License:Open Source License

public void asyncFilePump() {
    Vertx vertx = Vertx.vertx();//from  w  w  w . j a  v a  2 s  .co  m
    final AsyncFile output = vertx.fileSystem().openBlocking("target/classes/plagiary.txt", new OpenOptions());

    vertx.fileSystem().open("target/classes/les_miserables.txt", new OpenOptions(), result -> {
        if (result.succeeded()) {
            AsyncFile file = result.result();
            Pump.pump(file, output).start();
            file.endHandler((r) -> {
                System.out.println("Copy done");
            });
        } else {
            System.err.println("Cannot open file " + result.cause());
        }
    });
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example44(HttpClientRequest request, AsyncFile file) {

    request.setChunked(true);/*from  w w  w .j a v a 2  s  .  co  m*/
    Pump pump = Pump.pump(file, request);
    file.endHandler(v -> request.end());
    pump.start();

}

From source file:info.freelibrary.pairtree.s3.S3Client.java

License:Open Source License

/**
 * Uploads the file contents to S3./*  w  w w  .  j  a  va  2  s  .co  m*/
 *
 * @param aBucket An S3 bucket
 * @param aKey An S3 key
 * @param aFile A file to upload
 * @param aHandler A response handler for the upload
 */
public void put(final String aBucket, final String aKey, final AsyncFile aFile,
        final Handler<HttpClientResponse> aHandler) {
    final S3ClientRequest request = createPutRequest(aBucket, aKey, aHandler);
    final Buffer buffer = Buffer.buffer();

    aFile.endHandler(event -> {
        request.putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length()));
        request.end(buffer);
    });

    aFile.handler(data -> {
        buffer.appendBuffer(data);
    });
}