0 Replies Latest reply on Jan 5, 2011 9:23 PM by martypitt1

    Serializing InputStream as ByteArray using BeanProxy

    martypitt1 Level 1

      [Note:  Also posted on StckOverflow here]

       

      I'm trying to serialize an object which has an InputStream.  I need it to arrive on the flex client as a ByteArray.

       

      Note - I can't implement `IExternalizable` on this class, as it's not mine.

       

      I've registered a custom `BeanProxy` to do the conversion, however it doesn't appear to be working:

       

         public class InputStreamBeanProxy extends BeanProxy {
              @Override
              public Object getInstanceToSerialize(Object instance) {
             
                  InputStream stream = (InputStream) instance;
                  Byte[] boxOfBytes;
                      try {
                          byte[] bytes = IOUtils.toByteArray(stream);
                          boxOfBytes = new Byte[bytes.length];
                          for (int i=0; i < bytes.length; i++)
                          {
                             boxOfBytes[i] = bytes[i];
                          }
                      } catch (IOException e) {
                          logger.error("Exception serializing inputStream: ", e);
                          throw new RuntimeException(e);
                      }
                      return boxOfBytes;
                 }
          }

       

      This proxy is then registered during startup as follows:

       

          PropertyProxyRegistry.getRegistry().register(InputStream.class, new InputStreamBeanProxy());

       

      I've set breakpoints in this code, and I see it being called as expected.  However when the object arrives on the client, the input stream is typed as `Object`, and it contains no properties.

       

      What am I doing wrong?

       

      Thanks,

       

      Marty