List of usage examples for java.io FilterInputStream FilterInputStream
protected FilterInputStream(InputStream in)
FilterInputStream
by assigning the argument in
to the field this.in
so as to remember it for later use. 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; }