I have a gzipped JSON resource in my application that I want to serve up via a servlet. Browsers disagree on exactly why, but none of them will actually load my content. Does something look wrong with this code?
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(200);
InputStream in = <get an input stream to my gzipped data>;
resp.setIntHeader("Content-Length", in.available());
OutputStream out = resp.getOutputStream();
out.write(IOUtils.toByteArray(in));
out.close();
resp.setHeader("Content-Encoding", "gzip");
resp.setHeader("Content-Type", "application/json");
}
}