Example usage for org.apache.http.impl.io ChunkedOutputStream ChunkedOutputStream

List of usage examples for org.apache.http.impl.io ChunkedOutputStream ChunkedOutputStream

Introduction

In this page you can find the example usage for org.apache.http.impl.io ChunkedOutputStream ChunkedOutputStream.

Prototype

@Deprecated
    public ChunkedOutputStream(SessionOutputBuffer sessionOutputBuffer) throws IOException 

Source Link

Usage

From source file:org.apache.axis2.transport.http.server.AxisHttpConnectionImpl.java

public void sendResponse(final HttpResponse response) throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }/*  w  w  w  .j  a v  a  2s.  c  om*/

    if (HEADERLOG.isDebugEnabled()) {
        HEADERLOG.debug("<< " + response.getStatusLine().toString());
        for (HeaderIterator it = response.headerIterator(); it.hasNext();) {
            HEADERLOG.debug("<< " + it.nextHeader().toString());
        }
    }

    this.responseWriter.write(response);

    // Prepare output stream
    this.out = null;
    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
            this.out = new ChunkedOutputStream(this.outbuffer);
        } else if (len >= 0) {
            this.out = new ContentLengthOutputStream(this.outbuffer, len);
        } else {
            this.out = new IdentityOutputStream(this.outbuffer);
        }
    } else {
        this.outbuffer.flush();
    }
}

From source file:net.oneandone.sushi.fs.webdav.WebdavNode.java

@Override
public OutputStream createOutputStream(boolean append)
        throws CreateOutputStreamException, FileNotFoundException {
    byte[] add;// w  ww  .  ja va2 s  . c  om
    final Put method;
    final WebdavConnection connection;
    OutputStream result;

    try {
        if (isDirectory()) {
            throw new FileNotFoundException(this);
        }
    } catch (ExistsException e) {
        throw new CreateOutputStreamException(this, e);
    }
    try {
        if (append) {
            try {
                add = readBytes();
            } catch (FileNotFoundException e) {
                add = null;
            }
        } else {
            add = null;
        }
        synchronized (tryLock) {
            tryDir = false;
            method = new Put(this);
            connection = method.request();
            result = new ChunkedOutputStream(connection.getOutputBuffer()) {
                private boolean closed = false;

                @Override
                public void close() throws IOException {
                    if (closed) {
                        return;
                    }
                    closed = true;
                    super.close();
                    method.response(connection);
                }
            };
            if (add != null) {
                result.write(add);
            }
        }
        return result;
    } catch (IOException e) {
        throw new CreateOutputStreamException(this, e);
    }
}