Example usage for java.io FilterInputStream FilterInputStream

List of usage examples for java.io FilterInputStream FilterInputStream

Introduction

In this page you can find the example usage for java.io FilterInputStream FilterInputStream.

Prototype

protected FilterInputStream(InputStream in) 

Source Link

Document

Creates a FilterInputStream by assigning the argument in to the field this.in so as to remember it for later use.

Usage

From source file:davmail.exchange.dav.DavExchangeSession.java

protected InputStream getContentInputStream(String url) throws IOException {
    String encodedUrl = encodeAndFixUrl(url);

    final GetMethod method = new GetMethod(encodedUrl);
    method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    method.setRequestHeader("Translate", "f");
    method.setRequestHeader("Accept-Encoding", "gzip");

    InputStream inputStream;//from  w  w w.  java 2  s .com
    try {
        DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
        if (DavGatewayHttpClientFacade.isGzipEncoded(method)) {
            inputStream = new GZIPInputStream(method.getResponseBodyAsStream());
        } else {
            inputStream = method.getResponseBodyAsStream();
        }
        inputStream = new FilterInputStream(inputStream) {
            int totalCount;
            int lastLogCount;

            @Override
            public int read(byte[] buffer, int offset, int length) throws IOException {
                int count = super.read(buffer, offset, length);
                totalCount += count;
                if (totalCount - lastLogCount > 1024 * 128) {
                    DavGatewayTray.debug(new BundleMessage("LOG_DOWNLOAD_PROGRESS",
                            String.valueOf(totalCount / 1024), method.getURI()));
                    DavGatewayTray.switchIcon();
                    lastLogCount = totalCount;
                }
                return count;
            }

            @Override
            public void close() throws IOException {
                try {
                    super.close();
                } finally {
                    method.releaseConnection();
                }
            }
        };

    } catch (HttpException e) {
        method.releaseConnection();
        LOGGER.warn("Unable to retrieve message at: " + url);
        throw e;
    }
    return inputStream;
}