I am trying to read a HTTP uploaded file using FilePostParser and
PostFileInputStream.
I can read the file byte by byte, but if I try to read it in chunks I get an
AIOB exception. Here's my code with a comment on the line that blows up.
More commentary below.
---------

    Hashtable params = new Hashtable();
    Enumeration enumeration = new FilePostParser(req.getInputStream(),
req.getContentLength());
    while(enumeration.hasMoreElements()) {
      Object element = enumeration.nextElement();
      if(element instanceof Map.Entry) {
        Map.Entry entry = (Map.Entry) element;
        params.put(entry.getKey(), entry.getValue());
        }
      else if(element instanceof InputStream) {
        PostFileInputStream in = (PostFileInputStream) element;
        int len;
        byte[] b = new byte[1024];
        // PROBLEM: read throws an exception
        while ((len = in.read(b)) != -1) {
          out.write(b, 0, len);
          }
        out.close();
        }
      }
-----------
Now, according to the api docs, a InputStream.read(byte[]) should read in as
many bytes
as available and return the number of bytes read, or -1 if the stream is at
the end.
This is espescially confusing because if I read the file byte by byte, such
as:
        while ((len = in.read()) != -1) {
          out.write(len);
          }
It works just fine. Here is the exception I am getting.
---------
9/27/00 3:19 PM default: Servlet error
java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at com.evermind.io.PostFileInputStream.read(JAX)
        at java.io.InputStream.read(InputStream.java:91)
        at org.ancienttruth.servlets.UploadImage.doPost(UploadImage.java:62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at com.evermind.server.http.d1.si(JAX)
        at com.evermind.server.http.d1.forward(JAX)
        at com.evermind.server.http.ed.sp(JAX)
        at com.evermind.server.http.ed.so(JAX)
        at com.evermind.util.f.run(JAX)
----------
I am guessing this is a bug in the implementation, but I just wanted to ask
if there was
anything I am missing first. Thanks!

------
Jason von Nieda
3Buddies.com


Reply via email to