List of usage examples for org.apache.commons.httpclient ContentLengthInputStream ContentLengthInputStream
public ContentLengthInputStream(InputStream paramInputStream, long paramLong)
From source file:org.mule.transport.http.HttpRequest.java
public HttpRequest(final RequestLine requestLine, final Header[] headers, final InputStream content, String defaultEncoding) throws IOException { super();/*from w w w.ja v a2s . c o m*/ if (requestLine == null) { throw new IllegalArgumentException("Request line may not be null"); } this.defaultEncoding = defaultEncoding; this.requestLine = requestLine; if (headers != null) { this.headers.setHeaders(headers); } if (content != null) { // only PUT and POST have content String methodname = requestLine.getMethod(); if (HttpConstants.METHOD_POST.equalsIgnoreCase(methodname) || HttpConstants.METHOD_PUT.equalsIgnoreCase(methodname)) { Header contentLength = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_LENGTH); Header transferEncoding = this.headers.getFirstHeader(HttpConstants.HEADER_TRANSFER_ENCODING); InputStream in = content; if (transferEncoding != null) { if (transferEncoding.getValue().indexOf(HttpConstants.TRANSFER_ENCODING_CHUNKED) != -1) { in = new ChunkedInputStream(in); } } else if (contentLength != null) { long len = getContentLength(); if (len >= 0) { in = new ContentLengthInputStream(in, len); } } this.entity = in; } } }
From source file:org.mule.transport.http.HttpResponse.java
public HttpResponse(final StatusLine statusline, final Header[] headers, final InputStream content) throws IOException { super();//from ww w. ja v a2s.c o m if (statusline == null) { throw new IllegalArgumentException("Status line may not be null"); } setStatusLine(HttpVersion.parse(statusline.getHttpVersion()), statusline.getStatusCode(), statusline.getReasonPhrase()); setHeaders(headers); if (content != null) { InputStream in = content; Header contentLength = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_LENGTH); Header transferEncoding = this.headers.getFirstHeader(HttpConstants.HEADER_TRANSFER_ENCODING); if (transferEncoding != null) { if (transferEncoding.getValue().indexOf(HttpConstants.TRANSFER_ENCODING_CHUNKED) != -1) { in = new ChunkedInputStream(in); } } else if (contentLength != null) { long len = getContentLength(); if (len >= 0) { in = new ContentLengthInputStream(in, len); } } } }