java.io.IOException: reading encoded JPEG Stream messages in servlet logs

Article ID: 2456
Last updated: 29 May, 2018
Article ID: 2456
Last updated: 29 May, 2018
Revision: 3
Views: 1134
Posted: 27 Oct, 2006
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

Why do I get many java.io.IOException: reading encoded JPEG Stream messages in my servlet logs?

Cause

In some situations, your servlet may have a log file with several messages like:

java.io.IOException: reading encoded JPEG Stream 
at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native Method)
at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:472)
at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:228)
at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:235)
[...]
at .doGet(Unknown Source)

Answer

This exception can happen when the client requests a server update and then closes the connection while JViews servlet is in process of encoding the image onto the output stream. This typically occurs when the user requests a new update before receiving the response from the previous request.

These exceptions are harmless. However, if you do not want the exception to show up in the logs, you can workaround the problem by calling IlvManagerServletSupport.setContentLengthEnable(true). This will force the response to be encoded onto a separate buffer instead of directly into the response stream.

Alternatively, or if you are using JViews Charts where IlvManagerServletSupport is not available, you should catch the exception before it gets to the application server.

For instance, if you have overridden the doGet method of the servlet, you can also catch and test the exception.

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response) {
    try {
        super.doGet(request, response);
    } catch (java.io.IOException ex) {
        String message = ex.getMessage();
        boolean harmless = /*test if the message is the harmless JPEG exception*/;
        if (!harmless) {
            throw (ex);
        } // else do nothing.
    }
}

This will process each exception, and silently hide all of the harmless JPEG exceptions, while rethrowing other exceptions that may be caught elsewhere or printed.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2456
Last updated: 29 May, 2018
Revision: 3
Views: 1134
Posted: 27 Oct, 2006 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category