Package org.apache.http

Examples of org.apache.http.HttpEntity.writeTo()


        byte[] bytes2 = out.toByteArray();
        assertNotNull(bytes2);
        assertEquals(1, bytes2.length);
       
        try {
            httpentity.writeTo(null);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here


        connState.setOutputState(ServerConnState.RESPONSE_SENT);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            OutputStream outstream = new ContentOutputStream(buffer);
            entity.writeTo(outstream);
            outstream.flush();
            outstream.close();
        } else {
            connState.resetOutput();
            if (!this.connStrategy.keepAlive(response, context)) {
View Full Code Here

        if (response.getEntity() != null) {
            ContentOutputBuffer buffer = connState.getOutbuffer();
            OutputStream outstream = new ContentOutputStream(buffer);

            HttpEntity entity = response.getEntity();
            entity.writeTo(outstream);
            outstream.flush();
            outstream.close();
        }
       
        synchronized (connState) {
View Full Code Here

        HttpEntity entity = request.getBody().getEntity();
        if (async) {
          reqObj.setHeader(entity.getContentType());
          try {
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            entity.writeTo(output);
            NByteArrayEntity en = new NByteArrayEntity(output.toByteArray());
            ((HttpEntityEnclosingRequestBase) reqObj).setEntity(en);
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
View Full Code Here

                        }

                        HttpEntity entity = request.getEntity();
                        OutputStream outstream = new ContentOutputStream(
                                connState.getOutbuffer());
                        entity.writeTo(outstream);
                        outstream.flush();
                        outstream.close();

                        synchronized (connState) {
                            connState.setWorkerRunning(false);
View Full Code Here

        if (response.getEntity() != null) {
            ContentOutputBuffer buffer = connState.getOutbuffer();
            OutputStream outstream = new ContentOutputStream(buffer);

            HttpEntity entity = response.getEntity();
            entity.writeTo(outstream);
            outstream.flush();
            outstream.close();
        }

        synchronized (connState) {
View Full Code Here

            // If the request entity is repeatable, we can send it first to
            // our own stream, so we can return it
            final HttpEntity entityEntry = entity.getEntity();
            if(entityEntry.isRepeatable()) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                entityEntry.writeTo(bos);
                bos.flush();
                // We get the posted bytes using the charset that was used to create them
                entityBody.append(new String(bos.toByteArray(), charset));
                bos.close();
            }
View Full Code Here

        int statusCode = response.getStatusLine().getStatusCode();
     
        HttpEntity entity = response.getEntity();
        if (entity != null && statusCode == 200) {
          FileOutputStream fos = new java.io.FileOutputStream(file.getAbsolutePath());
          entity.writeTo(fos);
          fos.close();
        }
      } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
View Full Code Here

            File destFile = new File(filePath + File.separator + name);
            if (!destFile.exists()) {
                destFile.createNewFile();
            }
            FileOutputStream outputStream = new FileOutputStream(destFile);
            entity.writeTo(outputStream);
            return new File(destFile.getAbsolutePath());
        } catch (IOException e) {
            s_logger.debug("Faild to get url:"+ url + ", due to " + e.toString());
            throw new CloudRuntimeException(e);
        }
View Full Code Here

            HttpGet getMethod = new HttpGet(templateUrl);
            response = client.execute(getMethod);
            HttpEntity entity = response.getEntity();

            output = new BufferedOutputStream(new FileOutputStream(localFile));
            entity.writeTo(output);
        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.