package com.nyeggen.lash.serde;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**You should expect this to be pretty slow / inefficient, but it is a good
 * fallback implementation.*/
public class SerializingSerde implements Serde<Serializable> {
	private SerializingSerde(){}
	private static final SerializingSerde inst = new SerializingSerde();
	public static SerializingSerde getInstance(){ return inst; }
	
	@Override
	public Serializable fromBytes(byte[] d) {
		final ByteArrayInputStream bis = new ByteArrayInputStream(d);
		ObjectInput in = null;
		try {
		  in = new ObjectInputStream(bis);
		  return (Serializable)in.readObject();
		} catch(Exception e){
			throw new RuntimeException(e);
		} finally {
			try {
				bis.close();
			} catch (Exception e){
				throw new RuntimeException(e);
			}
		}
	}

	@Override
	public byte[] toBytes(Serializable t) {
		final ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutput out = null;
		try {
			out = new ObjectOutputStream(bos);
			out.writeObject(t);
			return bos.toByteArray();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			try {
				bos.close();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}
}

@@ -457,11 +457,12 @@
 de()
+ 
 %7B%7D%0A
-
 %09pri
@@ -572,16 +572,17 @@
 stance()
+ 
 %7B return
@@ -590,17 +590,16 @@
 inst; %7D%0A
-%09
 %0A%09@Overr
@@ -744,18 +744,17 @@
 try %7B%0A%09%09
-  
+%09
 in = new
@@ -784,10 +784,9 @@
 ;%0A%09%09
-  
+%09
 retu
@@ -802,16 +802,17 @@
 lizable)
+ 
 in.readO
@@ -829,16 +829,17 @@
 %09%7D catch
+ 
 (Excepti
@@ -839,24 +839,25 @@
 Exception e)
+ 
 %7B%0A%09%09%09throw n
@@ -912,32 +912,32 @@
 %09%09%09bis.close();%0A
-
 %09%09%09%7D catch (Exce
@@ -944,16 +944,17 @@
 ption e)
+ 
 %7B%0A%09%09%09%09th

Fix formatting for consistency