protected byte[] toBytes(T value) { return SerializationHelper.serialize( value ); }
/** * <p>Serializes an <code>Object</code> to a byte array for * storage/serialization.</p> * * @param obj the object to serialize to bytes * * @return a byte[] with the converted Serializable * * @throws SerializationException (runtime) if the serialization fails */ public static byte[] serialize(Serializable obj) throws SerializationException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( 512 ); serialize( obj, byteArrayOutputStream ); return byteArrayOutputStream.toByteArray(); }
private static void writeSerFile(Serializable binding, File xmlFile, File serFile) { try { log.debugf( "Writing cache file for: %s to: %s", xmlFile.getAbsolutePath(), serFile.getAbsolutePath() ); SerializationHelper.serialize( binding, new FileOutputStream( serFile ) ); boolean success = serFile.setLastModified( System.currentTimeMillis() ); if ( !success ) { log.warn( "Could not update cacheable hbm.xml bin file timestamp" ); } } catch ( Exception e ) { log.unableToWriteCachedFile( serFile.getAbsolutePath(), e.getMessage() ); } }
/** * <p>Deep clone an <code>Object</code> using serialization.</p> * <p/> * <p>This is many times slower than writing clone methods by hand * on all objects in your object graph. However, for complex object * graphs, or for those that don't support deep cloning this can * be a simple alternative implementation. Of course all the objects * must be <code>Serializable</code>.</p> * * @param object the <code>Serializable</code> object to clone * * @return the cloned object * * @throws SerializationException (runtime) if the serialization fails */ public static Object clone(Serializable object) throws SerializationException { LOG.trace( "Starting clone through serialization" ); if ( object == null ) { return null; } return deserialize( serialize( object ), object.getClass().getClassLoader() ); }
@Test public void testSerializeDeserialize() throws Exception { Class clazz = Thread.currentThread().getContextClassLoader().loadClass( "org.hibernate.test.util.SerializableThing" ); Object instance = clazz.newInstance(); // SerializableType.toBytes() logic, as called from SerializableType.disassemble() byte[] bytes = SerializationHelper.serialize( (Serializable) instance ); // SerializableType.fromBytes() logic, as called from SerializableType.assemble // NOTE : specifically we use Serializable.class.getClassLoader for the CL in many cases // which are the problematic cases Object instance2 = SerializationHelper.deserialize( bytes, Serializable.class.getClassLoader() ); assertEquals( instance.getClass(), instance2.getClass() ); assertEquals( instance.getClass().getClassLoader(), instance2.getClass().getClassLoader() ); assertEquals( custom, instance2.getClass().getClassLoader() ); }
public void testSerDeserClassUnknownToCustomLoader() throws Exception { Object instance = LockMode.OPTIMISTIC; assertSame( SerializationHelper.hibernateClassLoader(), instance.getClass().getClassLoader() ); // SerializableType.toBytes() logic, as called from SerializableType.disassemble() byte[] bytes = SerializationHelper.serialize( (Serializable) instance ); // SerializableType.fromBytes() logic, as called from SerializableType.assemble // NOTE : specifically we use custom so that LockType.class is not found // until the 3rd loader (because loader1 == loader2, the custom classloader) Object instance2 = SerializationHelper.deserialize( bytes, custom ); assertSame( instance.getClass(), instance2.getClass() ); assertSame( instance.getClass().getClassLoader(), instance2.getClass().getClassLoader() ); }
s.close(); foo = (Foo) SerializationHelper.deserialize( SerializationHelper.serialize(foo) );
SerializationHelper.deserialize( SerializationHelper.serialize(s) ); s.close();
byte[] bytes = SerializationHelper.serialize( s ); SerializationHelper.deserialize( bytes );
.addOrder( Order.asc("studentNumber") ); byte[] bytes = SerializationHelper.serialize(dc);
byte[] typeFactoryBytes = SerializationHelper.serialize( typeFactory );
private static byte[] toBytes(Object object) throws SerializationException { return SerializationHelper.serialize( (Serializable) object ); }
protected byte[] toBytes(T value) { return SerializationHelper.serialize( value ); }
protected byte[] toBytes(T value) { return SerializationHelper.serialize( value ); }
private static byte[] toBytes(Object object) throws SerializationException { return SerializationHelper.serialize( (Serializable) object ); }
protected byte[] toBytes(T value) { return SerializationHelper.serialize( value ); }
@Override public <X> X unwrap(T value, Class<X> type, SharedSessionContractImplementor session) { if ( type.equals( byte[].class ) ) { throw new UnsupportedOperationException( "Cannot unwrap Serializable to format other than byte[]" ); } return (X) SerializationHelper.serialize( value ); }
/** * <p>Serializes an <code>Object</code> to a byte array for * storage/serialization.</p> * * @param obj the object to serialize to bytes * * @return a byte[] with the converted Serializable * * @throws SerializationException (runtime) if the serialization fails */ public static byte[] serialize(Serializable obj) throws SerializationException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( 512 ); serialize( obj, byteArrayOutputStream ); return byteArrayOutputStream.toByteArray(); }
private static void writeSerFile(Serializable binding, File xmlFile, File serFile) { try { log.debugf( "Writing cache file for: %s to: %s", xmlFile.getAbsolutePath(), serFile.getAbsolutePath() ); SerializationHelper.serialize( binding, new FileOutputStream( serFile ) ); boolean success = serFile.setLastModified( System.currentTimeMillis() ); if ( !success ) { log.warn( "Could not update cacheable hbm.xml bin file timestamp" ); } } catch ( Exception e ) { log.unableToWriteCachedFile( serFile.getAbsolutePath(), e.getMessage() ); } }