List of usage examples for org.apache.http.entity InputStreamEntity InputStreamEntity
public InputStreamEntity(InputStream inputStream, ContentType contentType)
From source file:org.apache.camel.component.http4.HttpEntityConverter.java
private static HttpEntity asHttpEntity(InputStream in, Exchange exchange) throws IOException { InputStreamEntity entity;//from ww w . j a va2 s . co m if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) { String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class); InputStream stream = GZIPHelper.compressGzip(contentEncoding, in); entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream ? stream.available() != 0 ? stream.available() : -1 : -1); } else { entity = new InputStreamEntity(in, -1); } if (exchange != null) { String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class); String contentType = ExchangeHelper.getContentType(exchange); entity.setContentEncoding(contentEncoding); entity.setContentType(contentType); } return entity; }
From source file:org.opencredo.cloud.storage.azure.model.InputStreamBlob.java
/** * @return//from w w w. j a v a 2 s.co m * @see org.opencredo.cloud.storage.azure.model.Blob#createRequestBody() */ @Override public HttpEntity createRequestBody() { // FIXME: Calculate size - currently is 0 return new InputStreamEntity(data, 0); }
From source file:com.strato.hidrive.api.connection.httpgateway.request.InputStreamPutRequest.java
@Override protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor) throws UnsupportedEncodingException { HttpPut httpPut = new HttpPut(requestUri + visitor.getHttpRequestParams()); httpPut.setEntity(new InputStreamEntity(getInputStream(), getStreamLength())); return httpPut; }
From source file:service.xml.YmlLoaderServiceTest.java
@Test public void test() { HttpClient client = new DefaultHttpClient(); try {/*from ww w . ja v a 2s . co m*/ Configuration config = new Configuration(IConstants.TEST_PROPERTIES); HttpPost post = new HttpPost(config.getConfigProperties().getProperty("test.url")); String testXmlPath = config.getConfigProperties().getProperty("test.xml.path"); assertNotNull(testXmlPath); logger.info("Working with xml: " + testXmlPath); InputStreamEntity entity = new InputStreamEntity(new FileInputStream(testXmlPath), -1); entity.setChunked(true); entity.setContentType("application/xml"); post.setEntity(entity); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { logger.info(line); assertEquals("Export complete", line); } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:com.strato.hidrive.api.connection.httpgateway.request.InputStreamPostRequest.java
@Override protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor) throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost(requestUri + visitor.getHttpRequestParams()); httpPost.setEntity(new InputStreamEntity(getInputStream(), getStreamLength())); return httpPost; }
From source file:ru.phsystems.irisx.voice.httpPOST.java
/** * This file will post the flac file to google and store the Json String in jsonResponse data member *//* w w w . j ava2 s .c om*/ private void postFLAC() { try { //long start = System.currentTimeMillis(); // Load the file stream from the given filename File file = new File(FLACFileName); InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1); // Set the content type of the request entity to binary octet stream.. Taken from the chunked post example HTTPClient reqEntity.setContentType("binary/octet-stream"); //reqEntity.setChunked(true); // Uncomment this line, but I feel it slows stuff down... Quick Tests show no difference // set the POST request entity... httppost.setEntity(reqEntity); //System.out.println("executing request " + httppost.getRequestLine()); // Create an httpResponse object and execute the POST HttpResponse response = httpclient.execute(httppost); // Capture the Entity and get content HttpEntity resEntity = response.getEntity(); //System.out.println(System.currentTimeMillis()-start); String buffer; jsonResponse = ""; br = new BufferedReader(new InputStreamReader(resEntity.getContent())); while ((buffer = br.readLine()) != null) { jsonResponse += buffer; } //System.out.println("Content: "+jsonResponse); // Close Buffered Reader and content stream. EntityUtils.consume(resEntity); br.close(); } catch (Exception ee) { // In the event this POST Request FAILED //ee.printStackTrace(); jsonResponse = "_failed_"; } finally { // Finally shut down the client httpclient.getConnectionManager().shutdown(); } }
From source file:de.shadowhunt.subversion.internal.UploadOperation.java
@Override protected HttpUriRequest createRequest() { final URI uri = URIUtils.createURI(repository, resource); final HttpPut request = new HttpPut(uri); if (lockToken != null) { request.addHeader("If", "<" + uri + "> (<" + lockToken + ">)"); }//from w w w.j a va 2 s . c o m request.setEntity(new InputStreamEntity(content, STREAM_WHOLE_CONTENT)); return request; }
From source file:org.sonatype.nexus.testsuite.deploy.nxcm970.ContinuousDeployer.java
public void run() { final HttpPut method = new HttpPut(targetUrl); method.setEntity(new InputStreamEntity(new EndlessBlockingInputStream(this), -1)); try {/*from w w w.java2 s .co m*/ result = httpClient.execute(method).getStatusLine().getStatusCode(); } catch (Exception e) { result = -2; e.printStackTrace(); } }
From source file:com.sun.identity.proxy.client.EntityRequest.java
/** * Creates a new entity enclosing request for the specified incoming proxy * request.//from w w w.java 2s. c o m * * @param request the incoming proxy request. */ public EntityRequest(Request request) { this.method = request.method; String contentEncoding = request.headers.first("Content-Encoding"); int contentLength = IntegerUtil.parseInt(request.headers.first("Content-Length"), -1); String contentType = request.headers.first("Content-Type"); InputStreamEntity entity = new InputStreamEntity(request.entity, contentLength); if (contentEncoding != null) { entity.setContentEncoding(contentEncoding); } if (contentType != null) { entity.setContentType(contentType); } setEntity(entity); }
From source file:com.yanzhenjie.andserver.handler.AssetsRequestHandler.java
@Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { InputStream stream = mAssetsWrapper.getInputStream(mFilePath); if (stream == null) { requestInvalid(response);//w w w . j a v a 2s. c om } else { response.setStatusCode(200); response.setEntity(new InputStreamEntity(stream, stream.available())); } }