@Override public InputStream getInputStream() throws IOException { InputStream inputStream = super.getInputStream(); if (inputStream != null) { String contentType = getContentType(); // Only filter text resources. Content type prefixes were obtained from here: // http://www.iana.org/assignments/media-types/media-types.xhtml if ((contentType == null) || !(contentType.startsWith("audio") || contentType.startsWith("image") || contentType.startsWith("model") || contentType.startsWith("video"))) { if ((contentType == null) || !contentType.startsWith("text")) { logger.debug("Content-Type is \"{0}\" which may not be a filterable text content type.", contentType); } Map<String, String> responseHeaders = getResponseHeaders(); String encoding = responseHeaders.get("Content-Encoding"); if (encoding == null) { encoding = getEncoding(); } String inputStreamAsString = ResourceUtil.toString(inputStream, encoding, getBufferSize()); inputStreamAsString = filter(inputStreamAsString); inputStream = ResourceUtil.toInputStream(inputStreamAsString, encoding); } else { logger.warn("Resource not filtered because it's Content-Type=[{0}] which is not a text content type.", contentType); } } return inputStream; }