code: public static <T extends Serializable> T deserializeFromStream(InputStream in, Class<T> type) throws ClassNotFoundException, IOException
  	{
  		ObjectInputStream objIn;
  		T obj;
  
  		if(in instanceof ObjectInputStream)
  			objIn = (ObjectInputStream)in;
  		else
  			objIn = new ObjectInputStream(in);
  
  		obj = type.cast(objIn.readObject());
  		// to close or not to close... That is the question...
  		// we close... It doesn't make too much sense to have a stream with more afterwards...There would be two
  		// stream headers...
  		objIn.close();
  		return obj;
  	}
docs: Read one serialized object from a input stream.
  @param in InputStream to read from. This will be closed!
  @param type The type that is to be read.
  @return The serialized object cast as type.