Code example for ByteArrayOutputStream

Methods: closetoByteArray

0
		if(o == null) {
			throw new NullPointerException("Can't serialize null");
		} 
		byte[] rv=null;
		try { 
			ByteArrayOutputStream bos=new ByteArrayOutputStream();
			ObjectOutputStream os=new ObjectOutputStream(bos);
			os.writeObject(o);
			os.close();
			bos.close();
			rv=bos.toByteArray();
		} catch(IOException e) {
			throw new IllegalArgumentException("Non-serializable object", e);
		} 
		return rv;
	} 
 
	/** 
	 * Get the object represented by the given serialized bytes. 
	 */