On Sep 9, 2:20 pm, Vince Bonfanti <[email protected]> wrote:
> I'm trying to send binary data--a serialized Java object--via the
> TaskOptions.payload() method, but can't figure out how to send and/or
> read the data properly. First, I serialized an object to a byte[],
> which I know is working properly. Then I set the byte[] as the task
> payload via:
>
>     TaskOptions.payload( byte[], contentType );
>
> I've tried different values for contentType;
> "application/octet-stream" and "application/x-java-serialized-object"
> seemed like the two most reasonable, but this seems to have no effect.
>
> In my task handler (a servlet), I read the data into a byte[] prior to
> object deserialization via the following:
>
>    byte[] bytesIn = new byte[ req.getContentLength() ];
>    req.getInputStream().readLine( bytesIn, 0, bytesIn.length );
>
> However, the byte[] I read in is not the same as the byte[] I wrote
> out. Here are the first few bytes of the array as I wrote it to
> TaskOptions.payload (this is cut-and-paste from the Eclipse debugger):
>
>    -84, -19, 0, 5, 115, 114, 0, 38, 99, 111, 109, 46, 103, 111,
>
> and here are the first few bytes I read in, which is tantalizingly
> close to what was written out:
>
>     63,  63, 5, 115, 114, 38, 99, 111, 109, 46, 103, 111
>
> So then I tried a different tack. I converted the byte[] to a string
> in the outward direction:
>
>    TaskOptions.payload( new String( byte[] ) );

Don't do that, ever. That creates a string from a byte array in the
platform default encoding. Do you know what the platform default
encoding is? On your development machine? On every GAE/J production
server? On every GAE/J production server three years from now? Do you
know whether the algorithm checks for valid byte sequences?

Cheers
Philippe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to