04 janeiro 2013

Using Coherence API to get POF bytes


Someone raised the question on how to use the Coherence API to get the bytes of an object in POF (Portable Object Format) programatically. So I came up with this small code that shows the very cool API simple usage :-)
   SimplePofContext spc = new SimplePofContext();
   spc.registerUserType(0, User.class, new UserSerializer()); 
   // consider UserSerializer as an implementation of PofSerializer
            
   User u = new User();
   u.setId(21);
   u.setName("Some Name");
   u.setEmail("some.name@domain.com");
            
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutput dataOutput = new DataOutputStream(baos);
   BufferOutput bufferOutput = new WrapperBufferOutput(dataOutput);
   spc.serialize(bufferOutput, u);
            
   byte[] byteArray = baos.toByteArray();
   System.out.println(Arrays.toString(byteArray));
 Easy, isn't?
It can be easier with this line: ExternalizableHelper.toByteArray(Object, PofContext)
https://blogs.oracle.com/brunoborges/entry/coherence_pof_for_raw_byte

Nenhum comentário:

Contato

Email:bruno.borges(at)gmail.com

LinkedIn: www.linkedin.com/in/brunocborges
Twitter: www.twitter.com/brunoborges
Comprei e Não Vou
Rio de Janeiro, RJ Brasil
Oracle
São Paulo, SP Brasil