View Javadoc

1   /**********************************************************************
2    * ObjectStreamAdapter.java
3    * created on 13.08.2004 by netseeker
4    * $Source: /cvsroot/ejoe/EJOE/src/de/netseeker/ejoe/adapter/ObjectStreamAdapter.java,v $
5    * $Date: 2006/02/04 14:16:49 $
6    * $Revision: 1.8 $
7    *********************************************************************/
8   
9   package de.netseeker.ejoe.adapter;
10  
11  import java.io.IOException;
12  import java.io.InputStream;
13  import java.io.ObjectInputStream;
14  import java.io.ObjectOutputStream;
15  import java.io.OutputStream;
16  
17  /***
18   * Simple (de)serialize adapter using the standard ObjectInputStream and
19   * ObjectoutputStream classes provided by SUN.
20   * 
21   * @author netseeker aka Michael Manske
22   */
23  public class ObjectStreamAdapter implements SerializeAdapter
24  {
25  	/*
26  	 * (non-Javadoc)
27  	 * 
28  	 * @see de.netseeker.ejoe.adapter.SerializeAdapter#read(java.io.InputStream)
29  	 */
30  	public Object read(InputStream in) throws IOException
31  	{
32  		Object obj = null;
33  		ObjectInputStream oin = new ObjectInputStream(in);
34  
35  		try
36  		{
37  			obj = oin.readObject();
38  		}
39  		catch (ClassNotFoundException e)
40  		{
41  			throw new RuntimeException(e);
42  		}
43  
44  		return obj;
45  	}
46  
47  	/*
48  	 * (non-Javadoc)
49  	 * 
50  	 * @see de.netseeker.ejoe.adapter.SerializeAdapter#write(java.lang.Object,
51  	 *      java.io.OutputStream)
52  	 */
53  	public void write(Object obj, OutputStream out) throws IOException
54  	{
55  		ObjectOutputStream oout = new ObjectOutputStream(out);
56  		oout.writeObject(obj);
57  	}
58  
59  	/*
60  	 * (non-Javadoc)
61  	 * 
62  	 * @see de.netseeker.ejoe.adapter.SerializeAdapter#handleClassLoaderChange(java.lang.ClassLoader)
63  	 */
64  	public void handleClassLoaderChange(ClassLoader classLoader)
65  	{
66  		throw new UnsupportedOperationException(
67  				"ObjectStreamAdapter uses Suns ObjectInputStream internally which doesn't support usage of context classloaders. You can use the XStreamAdapter instead.");
68  	}
69  }