Example usage for org.eclipse.jgit.util HttpSupport HDR_CONTENT_ENCODING

List of usage examples for org.eclipse.jgit.util HttpSupport HDR_CONTENT_ENCODING

Introduction

In this page you can find the example usage for org.eclipse.jgit.util HttpSupport HDR_CONTENT_ENCODING.

Prototype

String HDR_CONTENT_ENCODING

To view the source code for org.eclipse.jgit.util HttpSupport HDR_CONTENT_ENCODING.

Click Source Link

Document

The Content-Encoding header.

Usage

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

License:Open Source License

/**
 * Gets an input stream to read the content from the specified request,
 * expanded it from GZIP format if necessary.
 *
 * @param request the request//  w  w  w . j  av  a 2  s  .  c o m
 * @return an input stream to read the content from the request
 * @throws IOException if an I/O error occurs
 */
public static InputStream inputStreamForRequest(WORequest request) throws IOException {
    InputStream input = request.content().stream();
    String encoding = request.headerForKey(HttpSupport.HDR_CONTENT_ENCODING);

    if (HttpSupport.ENCODING_GZIP.equals(encoding) || "x-gzip".equals(encoding)) {
        input = new GZIPInputStream(input);
    } else if (encoding != null) {
        throw new IOException("Content encoding \"" + encoding + "\" is " + "not supported.");
    }

    return input;
}

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

License:Open Source License

/**
 * Prepares a byte array to be appended to a response, by compressing it
 * (if the request supports that) as well as setting its etag header.
 *
 * @param content the raw content to send
 * @param request the request//from w ww .j  a v a2  s .c  o  m
 * @param response the response
 * @return the byte array that should be sent (which may be a compressed
 *     version of the one sent in)
 * @throws IOException if an I/O error occurs
 */
private static byte[] preSend(byte[] content, WORequest request, WOResponse response) throws IOException {
    response.setHeader(etag(content), HttpSupport.HDR_ETAG);

    if (content.length > 256 && acceptsGZIPEncoding(request)) {
        content = compressBytes(content);
        response.setHeader(HttpSupport.ENCODING_GZIP, HttpSupport.HDR_CONTENT_ENCODING);
    }

    return content;
}

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();/*from  w  w  w.j a  v a2 s .c  om*/

                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());
}