https://issues.apache.org/bugzilla/show_bug.cgi?id=48105

           Summary: Transfering PNG using getResponse()
           Product: Tomcat 5
           Version: 5.5.28
          Platform: PC
        OS/Version: Windows Server 2003
            Status: NEW
          Severity: critical
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: stefan.schumac...@ids-scheer.com


Hello,

within my action code I try to transfer my png files to browser using
getResponse().getOutputStream()). 

protected ActionForward executeInternal() throws Exception {

        FileInputStream in = null;
        ServletOutputStream out = null;
        try {
            String sFileName = getRequest().getParameter("img");
            long length = new File(sFileName).length();
            getResponse().setContentType("image/png");
            getResponse().setContentLength((int) length);

            in = new FileInputStream(sFileName);
            out = getResponse().getOutputStream();

            if (length > Integer.MAX_VALUE) {
                ABPLogger.getErrorLogger().severe("**File is too large");
                byte[] buf = new byte[4096];
                int len;
                while( (len = in.read(buf)) > 0 ) {
                    out.write(buf, 0, len);
                }
            }
            else {
                //Read/Write out in one block!!!!
                byte[] bytes = new byte[(int) length];
                in.read(bytes);
                out.write(bytes);
            }
        } catch (Exception ex) {
           getErrorLogger().severe("**TomCat streaming problem!!!!!");
           ex.printStackTrace();
        } finally {
            ABPResourceHelper.close(in);
        }
        return null;
    }


But very often following excpetion occurs.

jIT_121c9dc019d_SEVERE 2009-06-10T14:09:47,293 java.lang.System.arraycopy
Version 7.1.0.${p4.changelist}
Struts Action.execute() returns no ActionForward.
Query:
/modelgraphic.do?IDSConversationID=ID_5&img=NSN%20approvedffffffffd623bca8409/c967fee0-46be-11de-27ff-001e0b6f107a_100.png

java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:346)
    at
org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
    at
org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)

Within a second try it works well. What can I do to prevent this effect?

Thanks
Stefan

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to