Code example for ByteArrayInputStream

Methods: close

0
	public static Serializable serializableFromByteArray(byte[] bytes) {
		if (bytes == null) {
			return null; 
		} 
		long currentTimeMillis = System.currentTimeMillis();
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
		ObjectInput in = null;
		try { 
			in = new ObjectInputStream(bis);
			Serializable o;
 
			o = (Serializable) in.readObject();
			Log.d("deserializable", System.currentTimeMillis() - currentTimeMillis);
			return o;
		} catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
		} catch (IOException e) {
            throw new IllegalArgumentException(e);
		} finally { 
			try { 
				bis.close();
				in.close();
			} catch (IOException e) {
				//can be ignored 
			} 
		}