/** * <b>INTENDED FOR TESTSUITE USE ONLY!</b> * <p/> * Much like {@link #addCacheableFile(File)} except that here we will fail immediately if * the cache version cannot be found or used for whatever reason * * @param xmlFile The xml file, not the bin! * * @return The dom "deserialized" from the cached file. * * @throws SerializationException Indicates a problem deserializing the cached dom tree * @throws FileNotFoundException Indicates that the cached file was not found or was not usable. */ public Configuration addCacheableFileStrictly(File xmlFile) throws SerializationException, FileNotFoundException { final File cachedFile = determineCachedDomFile( xmlFile ); final boolean useCachedFile = xmlFile.exists() && cachedFile.exists() && xmlFile.lastModified() < cachedFile.lastModified(); if ( ! useCachedFile ) { throw new FileNotFoundException( "Cached file could not be found or could not be used" ); } LOG.readingCachedMappings( cachedFile ); Document document = ( Document ) SerializationHelper.deserialize( new FileInputStream( cachedFile ) ); add( new XmlDocumentImpl( document, "file", xmlFile.getAbsolutePath() ) ); return this; }
public Serializable disassemble(Object value) throws HibernateException { final Serializable result; if (value == null) { result = null; } else { final Object deepCopy = deepCopy(value); if (!(deepCopy instanceof Serializable)) { throw new SerializationException(String.format("deepCopy of %s is not serializable", value), null); } result = (Serializable) deepCopy; } return result; }
public static SessionQueryBag loadSessionQueryBagFromDB(HttpSession session , Long userId){ SessionQueryBag queryBag = null; UserQuery userQuery = null; if(userId != null){ userQuery = myListLoader.loadUserQuery(userId); if(userQuery != null && userQuery.getQueryContent()!= null){ session.setAttribute(RembrandtConstants.USER_QUERY, userQuery); byte[] objectData = userQuery.getQueryContent(); Object obj = null; try { obj = SerializationHelper.deserialize(objectData); if(obj != null && obj instanceof SessionQueryBag){ queryBag = (SessionQueryBag)obj; } } catch (SerializationException e) { System.out.println(e); logger.error(e.getMessage()); session.removeAttribute(RembrandtConstants.USER_QUERY); } }else{ session.removeAttribute(RembrandtConstants.USER_QUERY); } } return queryBag; }
private List<Field> indexFields(Schema schema, PropBagEx resBag) { List<Field> fields = new ArrayList<Field>(); if( schema != null ) { try { XmlSchemaIndexer schemaIndexer = new XmlSchemaIndexer(); schemaIndexer.indexChildNodes(schema.getRootSchemaNode(), schema.getItemNamePath(), "", "", resBag); //$NON-NLS-1$ //$NON-NLS-2$ fields.addAll(schemaIndexer.getIndexedFields()); Set<String> allPaths = schemaIndexer.getPathsIndexed(); for( String path : allPaths ) { fields.add(indexed(FreeTextQuery.FIELD_ALL, path)); } Map<String, StringBuilder> pathValuesMap = schemaIndexer.getPathValuesMap(); for( Map.Entry<String, StringBuilder> entry : pathValuesMap.entrySet() ) { fields.add(unstored(entry.getKey() + '*', entry.getValue().toString())); } } catch( SerializationException ex ) { LOGGER.error("Schema causing this issue is " + schema.getId() + " - " //$NON-NLS-1$ //$NON-NLS-2$ + schema.getUuid(), ex); throw ex; } } return fields; }
@Override public Serializable disassemble(Object value) throws HibernateException { Object copy = deepCopy(value); if (copy instanceof Serializable) { return (Serializable) copy; } throw new SerializationException( String.format("Cannot serialize '%s', %s is not Serializable.", value, value.getClass()), null); }
/** * <p>Serializes an <code>Object</code> to the specified stream.</p> * * <p>The stream will be closed once the object is written. * This avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param obj the object to serialize to bytes, may be null * @param outputStream the stream to write to, must not be null * @throws IllegalArgumentException if <code>outputStream</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static void serialize(Serializable obj, OutputStream outputStream) throws SerializationException { if (outputStream == null) { throw new IllegalArgumentException("The OutputStream must not be null"); } if ( log.isTraceEnabled() ) { if ( Hibernate.isInitialized( obj ) ) { log.trace( "Starting serialization of object [" + obj + "]" ); } else { log.trace( "Starting serialization of [uninitialized proxy]" ); } } ObjectOutputStream out = null; try { // stream closed in the finally out = new ObjectOutputStream(outputStream); out.writeObject(obj); } catch (IOException ex) { throw new SerializationException("could not serialize", ex); } finally { try { if (out != null) out.close(); } catch (IOException ignored) {} } }
protected byte[] toBytes(T value) { try { return OBJECT_MAPPER.writeValueAsBytes(value); } catch (Exception ex) { throw new SerializationException("could not serialize", ex); } }
protected T fromBytes(byte[] bytes) { try { return OBJECT_MAPPER.readValue(bytes, getJavaTypeClass()); } catch (Exception ex) { throw new SerializationException("could not deserialize", ex); } }
/** * Disassembles the object in preparation for serialization. * See {@link org.hibernate.usertype.UserType#disassemble(java.lang.Object)}. * <p> * Expects {@link #deepCopy(Object)} to return a {@code Serializable}. * <strong>Subtypes whose {@code deepCopy} implementation returns a * non-serializable object must override this method.</strong> */ @Override public Serializable disassemble(Object value) throws HibernateException { // also safe for mutable objects Object deepCopy = deepCopy(value); if (!(deepCopy instanceof Serializable)) { throw new SerializationException( String.format("deepCopy of %s is not serializable", value), null); } return (Serializable) deepCopy; }
private static byte[] toBytes(Object object) throws SerializationException { return SerializationHelper.serialize((Serializable) object); }
private static Object fromBytes(byte[] bytes) throws SerializationException { return SerializationHelper.deserialize(bytes); }
@LogMessage(level = WARN) @Message(value = "Could not deserialize cache file: %s : %s", id = 307) void unableToDeserializeCache(String path, SerializationException error);
/** * <p>Deep clone an <code>Object</code> using serialization.</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() ); }
/** * <p>Deserializes a single <code>Object</code> from an array of bytes.</p> * * @param objectData the serialized object, must not be null * @return the deserialized object * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(byte[] objectData) throws SerializationException { if (objectData == null) { throw new IllegalArgumentException("The byte[] must not be null"); } ByteArrayInputStream bais = new ByteArrayInputStream(objectData); return deserialize(bais); }
/** * <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(); }
/** * Deserializes an object from the specified stream using the Thread Context * ClassLoader (TCCL). * <p/> * Delegates to {@link #doDeserialize} * * @param inputStream the serialized object input stream, must not be null * * @return the deserialized object * * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(InputStream inputStream) throws SerializationException { return doDeserialize( inputStream, defaultClassLoader(), hibernateClassLoader(), null ); }
/** * Deserializes an object from the specified stream using the Thread Context * ClassLoader (TCCL). If there is no TCCL set, the classloader of the calling * class is used. * <p/> * The stream will be closed once the object is read. This avoids the need * for a finally clause, and maybe also exception handling, in the application * code. * <p/> * The stream passed in is not buffered internally within this method. This is * the responsibility of the caller, if desired. * * @param inputStream the serialized object input stream, must not be null * @param loader The classloader to use * * @return the deserialized object * * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(InputStream inputStream, ClassLoader loader) throws SerializationException { return doDeserialize( inputStream, loader, defaultClassLoader(), hibernateClassLoader() ); }
/** * Deserializes an object from an array of bytes using the Thread Context * ClassLoader (TCCL). If there is no TCCL set, the classloader of the calling * class is used. * <p/> * Delegates to {@link #deserialize(byte[], ClassLoader)} * * @param objectData the serialized object, must not be null * * @return the deserialized object * * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(byte[] objectData) throws SerializationException { return doDeserialize( wrap( objectData ), defaultClassLoader(), hibernateClassLoader(), null ); }
/** * Deserializes an object from an array of bytes. * <p/> * Delegates to {@link #deserialize(java.io.InputStream, ClassLoader)} using a * {@link ByteArrayInputStream} to wrap the array. * * @param objectData the serialized object, must not be null * @param loader The classloader to use * * @return the deserialized object * * @throws IllegalArgumentException if <code>objectData</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static Object deserialize(byte[] objectData, ClassLoader loader) throws SerializationException { return doDeserialize( wrap( objectData ), loader, defaultClassLoader(), hibernateClassLoader() ); }
/** * <p>Deep clone an <code>Object</code> using serialization.</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"); return deserialize( serialize(object) ); }
/** * <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 baos = new ByteArrayOutputStream(512); serialize(obj, baos); return baos.toByteArray(); }