0 Replies Latest reply on Apr 28, 2013 5:36 PM by toriacht

    Static utility methods to CDI

    toriacht

      Hi,

       

      I have a simple old style static methods in a utility class. I am struggling to "CDI" it due to the paramterised objects required each time..any help appreciated on how best to approach this?

       

      i.e. i would like to Inject the utility class into multiple classes and call the methods below (and similar) where required...The utility class would in turn inject the ByteArrayInputStream,ObjectInputStream each time with correct parameters...

       

       

      public class Utils {

       

       

                public static Object fromByteArray(final byte[] data) throws IOException, ClassNotFoundException {

       

                          final ByteArrayInputStream b = new ByteArrayInputStream(data);

                          final ObjectInputStream o = new ObjectInputStream(b);

                          return o.readObject();

                }

       

       

                public static byte[] toByteArray(final MyObj tx)  throws IOException{

                          final ByteArrayOutputStream b = new ByteArrayOutputStream();

                          final ObjectOutputStream o = new ObjectOutputStream(b);

                          o.writeObject(tx);

                          return b.toByteArray();

                }

       

      }

       

       

      Cheers...