Package org.apache.http

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


        throws IOException {
      super(target, request);
      HttpEntity entity = request.getEntity();
      // TODO 暂时把所有的请求先读入内存,在存在大文件的时候可能OutOfMemory,以后重写一个基于MultiPartInputStream来优化
      ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
      entity.writeTo(byteOutStream);
      httpInStream = new ByteArrayInputStream(
          byteOutStream.toByteArray());

      byteOutStream.close();
      contentLength = entity.getContentLength();
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

                }
            } else {
                final HttpEntityDigester entityDigester = new HttpEntityDigester(digester);
                try {
                    if (entity != null) {
                        entity.writeTo(entityDigester);
                    }
                    entityDigester.close();
                } catch (final IOException ex) {
                    throw new AuthenticationException("I/O error reading entity content", ex);
                }
View Full Code Here

        }
       
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);
       
        // Expect one connection in the pool
        assertEquals(1, mgr.getConnectionsInPool());

        // Make sure one connection is available
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

            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

            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

            // 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

        }

        final HttpEntity e = response.getEntity();
        Assert.assertNotNull(e);
        final ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);

        // Expect one connection in the pool
        stats = this.mgr.getTotalStats();
        Assert.assertEquals(1, stats.getAvailable());
View Full Code Here

                }
            } else {
                HttpEntityDigester entityDigester = new HttpEntityDigester(digester);
                try {
                    if (entity != null) {
                        entity.writeTo(entityDigester);
                    }
                    entityDigester.close();
                } catch (IOException ex) {
                    throw new AuthenticationException("I/O error reading entity content", ex);
                }
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.