users@jersey.java.net

Re: [Jersey] Multipart 1.0.3 not finding message body reader

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 22 Apr 2009 15:38:25 +0200

Hi,

I think your issue is the following:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#available()

             byte[] bytes = new byte[source.available()];
             source.read(bytes, 0, source.available());
             dto.setDataBytes(bytes);

the value returned from available can be '0' and MIMEPull returns 0.
The value indicates the number of bytes that can be read *without
blocking*. It does not indicate the number of bytes that can be read
in one call to read or the total number of bytes the stream contains.

You need to do something like this:

         private byte[] read(InputStream in) throws IOException {
             System.out.println(in.available());
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             byte[] buffer = new byte[4096];
             int read = -1;
             while ((read = in.read(buffer)) != -1) {
                 baos.write(buffer, 0, read);
             }

             return baos.toByteArray();
         }

Or instead just do:

   byte[] bytes =
multiPart.getBodyParts().get(1).getEntityAs(byte[].class);

Paul.

Also as of 1.0.3 you no longer need to call cleanup. It is done
automatically.
On Apr 22, 2009, at 2:23 PM, Ari Heino wrote:

> Here you go.
> Cheers,
>
> Ari
>
>
>
>
> Desktop.zip (3K) Download Attachment
>
> View this message in context: RE: [Jersey] Multipart 1.0.3 not
> finding message body reader
> Sent from the Jersey mailing list archive at Nabble.com.