hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Boxer, Aaron" <Aaron.Bo...@uhn.ca>
Subject RE: Need help with zero copy put
Date Wed, 15 Jan 2014 03:12:09 GMT
I have the following code that I am using with an httpclientasync client:

          void put(File file, Map<String, String> headers)
          {

              HttpPut put = new HttpPut(url);
              InputStream is = new FileInputStream(file);
              InputStreamEntity entity = new InputStreamEntity(dataStream, -1);
              put.setEntity(entity);
              for (String header : headers.keySet())
              {
                     put.addHeader(header, headers.get(header));
              }
              if (entity.getContentType() == null && !put.containsHeader(HttpHeaders.CONTENT_TYPE))
              {
                     put.addHeader(HttpHeaders.CONTENT_TYPE, HTTP.DEF_CONTENT_CHARSET.name());
              }
              Future<HttpResponse> rc = client.execute(put, context, null);

          }

I would like to use a ZeroCopyPut in this code to avoid the copy into user land. Is it possible
to do this?
I have seen the zero copy example, but I don't know how to adapt it to this function here.


Well, I figured it out:



ZeroCopyPut put = new ZeroCopyPut(
		       url,
		       file,
		        ContentType.DEFAULT_BINARY) {

		    @Override
		    protected HttpEntityEnclosingRequest createRequest(
		            final URI requestURI, final HttpEntity entity) {
		        HttpEntityEnclosingRequest request = super.createRequest(requestURI, entity);
		        request.addHeader(HttpHeaders.CONTENT_TYPE, HTTP.DEF_CONTENT_CHARSET.name());
		        return request;
		    }
		};
        Future<HttpResponse> future = client.execute(put, new BasicAsyncResponseConsumer(),
context, new FutureCallback<HttpResponse>(){

			@Override
			public void completed(HttpResponse result) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void failed(Exception ex) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void cancelled() {
				// TODO Auto-generated method stub
				
			}

			});




This e-mail may contain confidential and/or privileged information for the sole use of the
intended recipient. 
Any review or distribution by anyone other than the person for whom it was originally intended
is strictly prohibited. 
If you have received this e-mail in error, please contact the sender and delete all copies.

Opinions, conclusions or other information contained in this e-mail may not be that of the
organization.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message