Example usage for org.apache.http.nio.client.methods ZeroCopyPost ZeroCopyPost

List of usage examples for org.apache.http.nio.client.methods ZeroCopyPost ZeroCopyPost

Introduction

In this page you can find the example usage for org.apache.http.nio.client.methods ZeroCopyPost ZeroCopyPost.

Prototype

public ZeroCopyPost(final String requestURI, final File content, final ContentType contentType)
            throws FileNotFoundException 

Source Link

Usage

From source file:httpasync.ZeroCopyHttpExchange.java

public static void main(final String[] args) throws Exception {

    CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
    try {//from   w w w  . j  a  v a2s  .co  m
        httpclient.start();
        File upload = new File(args[0]);
        File download = new File(args[1]);
        ZeroCopyPost httpost = new ZeroCopyPost("http://localhost:8080/", upload,
                ContentType.create("text/plain"));
        ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {

            @Override
            protected File process(final HttpResponse response, final File file, final ContentType contentType)
                    throws Exception {
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                    throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
                }
                return file;
            }

        };
        Future<File> future = httpclient.execute(httpost, consumer, null);
        File result = future.get();
        System.out.println("Response file length: " + result.length());
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}

From source file:com.boonya.http.async.examples.nio.client.ZeroCopyHttpExchange.java

public static void main(final String[] args) throws Exception {
    CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
    try {//from   ww w.j  a v a  2s  .com
        httpclient.start();
        File upload = new File(args[0]);
        File download = new File(args[1]);
        ZeroCopyPost httpost = new ZeroCopyPost("http://localhost:8080/", upload,
                ContentType.create("text/plain"));
        ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {

            @Override
            protected File process(final HttpResponse response, final File file, final ContentType contentType)
                    throws Exception {
                if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                    throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
                }
                return file;
            }

        };
        Future<File> future = httpclient.execute(httpost, consumer, null);
        File result = future.get();
        System.out.println("Response file length: " + result.length());
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
    System.out.println("Done");
}