Java 8 Serializable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Serializable class.

This code example shows how to use the following methods:hashCode
 * The keys must have good <code>equals</code> and </code>hashCode</code> implementations and 
 * must respect the case-sensitivity of the use-case. 
 * <p> 
 * All keys will be unique to the given cache region, allowing the cache to be shared 
 * between instances of this class. 
 * <p> 
 * Generics: 
 * <ul> 
 *   <li>K:  The database unique identifier.</li> 
 *   <li>V:  The value stored against K.</li> 
 *   <li>VK: The a value-derived key that will be used as a cache key when caching K for lookups by V. 
 *           This can be the value itself if it is itself a good key.</li> 
 * </ul> 
 *  
 * @author Derek Hulley 
 * @since 3.2 
 */ 
public class EntityLookupCache<K extends Serializable, V extends Object, VK extends Serializable>
{ 
    /** 

6
CodeRank
This code example shows how to use the following methods:getIdentifier
            result = super.doInBackground();
 
            if (properties != null)
            { 
                String transitionIdentifier = "";
                if (task.getIdentifier().startsWith(WorkflowModel.KEY_PREFIX_ACTIVITI)) 
                { 
                    transitionIdentifier = WorkflowModel.TRANSITION_NEXT;
                } 
                if (!(session.getServiceRegistry().getWorkflowService() instanceof PublicAPIWorkflowServiceImpl)) 
                { 
                    properties.put(WorkflowModel.PROP_TRANSITIONS_VALUE, transitionIdentifier);
                } 
                updatedTask = session.getServiceRegistry().getWorkflowService().completeTask(task, properties);
            } 
        } 
        catch (Exception e)
        { 
            result.setException(e);
            Log.e(TAG, Log.getStackTraceString(e));
5
CodeRank
This code example shows how to use the following methods:equals
 
		if (id == null) {
			throw new IllegalArgumentException("find(class, id) has been given null id.  Class is " + cls.getName()
					+ "."); 
		} 
		else if (id.equals(0)) {
			throw new IllegalArgumentException("find(class, id) has been given zero id.  Class is " + cls.getName()
					+ "."); 
		} 
 
		try { 
			T obj = _em.find(cls, id);
 
			if (obj == null) {
				throw new DoesNotExistException(cls, id);
			} 
 
			return obj;
		} 
		catch (IllegalArgumentException e) {
5
CodeRank
This code example shows how to use the following methods:close, readObject
This code example shows how to use the following methods:readObject
	/** 
	 * Reads the input stream and deserializes into an object. 
	 */ 
	@Override 
	public Object deserialize(InputStream inputStream) throws IOException {
		ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
		try { 
			return objectInputStream.readObject();
		} 
		catch (ClassNotFoundException ex) {
			throw new NestedIOException("Failed to deserialize object type", ex);
		} 
	} 
 
} 
10
CodeRank
This code example shows how to use the following methods:available, close, readObject
        try { 
            ByteBuffer dup = bytes.duplicate();
            int l = dup.remaining();
            ByteArrayInputStream bais = new ByteArrayInputStream(dup.array(),
                    dup.arrayOffset() + dup.position(), l);
            ObjectInputStream ois = new ObjectInputStream(bais);
            Object obj = ois.readObject();
            dup.position(dup.position() + (l - ois.available()));
            ois.close();
            return obj; 
        } catch (Exception ex) {
            throw new SerializationException(ex);
        } 
    } 
 
    public static ObjectSerializer get() { 
        return INSTANCE;
    } 
} 
10
CodeRank
This code example shows how to use the following methods:close, writeObject
	@Override 
	public Object deepCopy(Object value) throws HibernateException {
		try { 
			// Write to new byte array to clone. 
			ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE);
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			try { 
				oos.writeObject(value);
			} 
			finally { 
				oos.close();
			} 
 
			// Read it back and return a true copy. 
			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
			ObjectInputStream ois = new ObjectInputStream(bais);
			try { 
				return ois.readObject();
			} 
			finally { 
10
CodeRank
This code example shows how to use the following methods:writeBoolean, writeInt, writeObject
This code example shows how to use the following methods:close, readObject
This code example shows how to use the following methods:writeObject
 */ 
public class SerializationTestUtils { 
 
	public static void testSerialization(Object o) throws IOException {
		OutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oos = new ObjectOutputStream(baos);
		oos.writeObject(o);
	} 
 
	public static boolean isSerializable(Object o) throws IOException {
		try { 
			testSerialization(o); 
			return true; 
		} 
		catch (NotSerializableException ex) {
			return false; 
		} 
	} 
 
	public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
9
CodeRank

Related Java 8 Serializable Questions & Answers:

See Code Examples for Java 8 Serializable Methods: