Package java.io

Examples of java.io.ObjectOutput


        return new DroolsObjectInputStream(new ByteArrayInputStream(buf)).readObject();
    }

    private static byte[] serialize(Object obj) throws IOException {
        ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
        ObjectOutput            out = new DroolsObjectOutputStream(bytes);

        out.writeObject(obj);
        out.flush();
        out.close();

        return bytes.toByteArray();
    }
View Full Code Here


        return new ObjectInputStream(new ByteArrayInputStream(buf)).readObject();
    }

    private static byte[] marshal(Object obj) throws IOException {
        ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
        ObjectOutput            out = new ObjectOutputStream(bytes);

        out.writeObject(obj);
        out.flush();
        out.close();

        return bytes.toByteArray();
    }
View Full Code Here

   }

   @Override
   protected ByteBuffer objectToBuffer(Object obj, int estimatedSize) throws IOException, InterruptedException {
      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
      ObjectOutput out = startObjectOutput(baos, false);
      try {
         defaultMarshaller.objectToObjectStream(obj, out);
      } catch (java.io.NotSerializableException nse) {
         if (log.isDebugEnabled()) log.debug("Object is not serializable", nse);
         throw new org.infinispan.marshall.NotSerializableException(nse.getMessage(), nse.getCause());
View Full Code Here

      return o;
   }

   @Override
   public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
      ObjectOutput out = defaultMarshaller.startObjectOutput(os, isReentrant);
      try {
         out.writeShort(VERSION_420);
         if (trace) log.trace("Wrote version {0}", VERSION_420);
      } catch (Exception e) {
         finishObjectOutput(out);
         log.error("Unable to read version id from first two bytes of stream, barfing.");
         throw new IOException("Unable to read version id from first two bytes of stream : " + e.getMessage());
View Full Code Here

      Query query = em.createQuery( "SELECT p FETCH JOIN p.distributors FROM Item p" );
      query.getSingleResult();
    }
    catch (IllegalArgumentException e) {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream( stream );
      out.writeObject( e );
      out.close();
      byte[] serialized = stream.toByteArray();
      stream.close();
      ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
      ObjectInputStream in = new ObjectInputStream( byteIn );
      IllegalArgumentException deserializedException = (IllegalArgumentException) in.readObject();
      in.close();
      byteIn.close();
      assertNull( deserializedException.getCause().getCause() );
      assertNull( e.getCause().getCause() );
    }
    em.getTransaction().rollback();
    em.close();


    Exception e = new HibernateException( "Exception", new NullPointerException( "NPE" ) );
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream( stream );
    out.writeObject( e );
    out.close();
    byte[] serialized = stream.toByteArray();
    stream.close();
    ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
    ObjectInputStream in = new ObjectInputStream( byteIn );
    HibernateException deserializedException = (HibernateException) in.readObject();
View Full Code Here

   }

   @Override
   protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException {
      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
      ObjectOutput marshaller = startObjectOutput(baos, false);
      try {
         objectToObjectStream(o, marshaller);
      } finally {
         finishObjectOutput(marshaller);
      }
View Full Code Here

*/
public class EntityManagerSerializationTest extends org.hibernate.ejb.test.TestCase {

  public void testSerialization() throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput out = new ObjectOutputStream( stream );
    out.writeObject( factory );
    out.close();
    byte[] serialized = stream.toByteArray();
    stream.close();
    ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
    ObjectInputStream in = new ObjectInputStream( byteIn );
    EntityManagerFactory seriallizedFactory = (EntityManagerFactory) in.readObject();
    in.close();
    byteIn.close();
    EntityManager em = seriallizedFactory.createEntityManager();
    //em.getTransaction().begin();
    //em.setFlushMode( FlushModeType.NEVER );
    Cat cat = new Cat();
    cat.setAge( 3 );
    cat.setDateOfBirth( new Date() );
    cat.setLength( 22 );
    cat.setName( "Kitty" );
    em.persist( cat );
    Item item = new Item();
    item.setName( "Train Ticket" );
    item.setDescr( "Paris-London" );
    em.persist( item );
    //em.getTransaction().commit();
    //em.getTransaction().begin();
    item.setDescr( "Paris-Bruxelles" );
    //em.getTransaction().commit();

    //fake the in container work
    ( (HibernateEntityManager) em ).getSession().disconnect();
    stream = new ByteArrayOutputStream();
    out = new ObjectOutputStream( stream );
    out.writeObject( em );
    out.close();
    serialized = stream.toByteArray();
    stream.close();
    byteIn = new ByteArrayInputStream( serialized );
    in = new ObjectInputStream( byteIn );
    em = (EntityManager) in.readObject();
View Full Code Here

      if (rawValue == null) {
         try {
            // Do NOT set instance to null over here, since it may be used elsewhere (e.g., in a cache listener).
            // this will be compacted by the MarshalledValueInterceptor when the call returns.
            ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(this.serialisedSize);
            ObjectOutput out = marshaller.startObjectOutput(baos, true);
            try {
               marshaller.objectToObjectStream(instance, out);
            } finally {
               marshaller.finishObjectOutput(out);
            }
View Full Code Here

  }

  public Reference getReference() throws NamingException {
        LOG.debugf( "Returning a Reference to the Ejb3Configuration" );
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput out = null;
    byte[] serialized;
    try {
      out = new ObjectOutputStream( stream );
      out.writeObject( this );
      out.close();
      serialized = stream.toByteArray();
      stream.close();
    }
    catch (IOException e) {
      NamingException namingException = new NamingException( "Unable to serialize Ejb3Configuration" );
View Full Code Here

        return new DroolsObjectInputStream(new ByteArrayInputStream(buf)).readObject();
    }

    private static byte[] serialize(Object obj) throws IOException {
        ByteArrayOutputStream   bytes   = new ByteArrayOutputStream();
        ObjectOutput            out = new DroolsObjectOutputStream(bytes);

        out.writeObject(obj);
        out.flush();
        out.close();

        return bytes.toByteArray();
    }
View Full Code Here

TOP

Related Classes of java.io.ObjectOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.