Example usage for org.eclipse.jgit.util TemporaryBuffer writeTo

List of usage examples for org.eclipse.jgit.util TemporaryBuffer writeTo

Introduction

In this page you can find the example usage for org.eclipse.jgit.util TemporaryBuffer writeTo.

Prototype

public void writeTo(OutputStream os, ProgressMonitor pm) throws IOException 

Source Link

Document

Send this buffer to an output stream.

Usage

From source file:org.webcat.core.http.SmartGZIPOutputStream.java

License:Open Source License

@Override
public void close() throws IOException {
    super.close();

    if (!startedOutput) {
        TemporaryBuffer out = this;

        if (out.length() > 256 && RequestUtils.acceptsGZIPEncoding(request)) {
            TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);

            try {
                GZIPOutputStream gzip = new GZIPOutputStream(gzbuf);
                out.writeTo(gzip, null);
                gzip.close();//w ww. j a v  a 2 s. c  o m

                if (gzbuf.length() < out.length()) {
                    out = gzbuf;
                    response.setHeader(HttpSupport.ENCODING_GZIP, HttpSupport.HDR_CONTENT_ENCODING);
                }
            } catch (IOException e) {
                // Likely caused by overflowing the buffer, meaning the
                // data would be larger if compressed. Discard compressed
                // copy and use the original.
            }
        }

        out.writeTo(outputStream, null);
        outputStream.flush();
    }

    // Finally, append whatever was dumped into our stream to the response
    // content.

    outputStream.close();
    response.appendContentData(outputStream.data());
}