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

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

Introduction

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

Prototype

@Override
    AsyncFile handler(Handler<Buffer> handler);

Source Link

Usage

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

License:Open Source License

/**
 * Uploads the file contents to S3.//from ww w.  j a  v a2  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);
    });
}