IoUtil { public static InputStream getRequestInputStream(HttpServletRequest request) throws IOException { InputStream bodyStream = request.getInputStream(); if (bodyStream != null && GZIP_ENCODING.equals(request.getHeader(HEADER_CONTENT_ENCODING))) { PushbackInputStream pushbackStream = new PushbackInputStream(bodyStream, 2); byte[] header = new byte[2]; int len = pushbackStream.read(header); if (len > 0) { pushbackStream.unread(header, 0, len); } return isGzipHeader(header) ? new GZIPInputStream(pushbackStream) : pushbackStream; } return bodyStream; } private  IoUtil(); static String readResourceFile(Class<?> c, String fileName); static void copy(InputStream in, File dest); static String readFile(File file); static List<String> readFiles(File directory, FileFilter filter); static String readStream(InputStream is); static InputStream getRequestInputStream(HttpServletRequest request); static String readRequestBody(HttpServletRequest request);  }
@Test public void testGetRequestInputStream() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setContent(compress("test".getBytes(StandardCharsets.UTF_8))); request.addHeader("Content-Encoding", "gzip"); InputStream stream = IoUtil.getRequestInputStream(request); assertThat(stream).isInstanceOf(GZIPInputStream.class); assertThat(IoUtil.readStream(stream)).isEqualTo("test"); }