package ViewManager;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;

import com.datastax.driver.core.utils.Bytes;

public class Serialize {

	public static ByteBuffer serializeStream(Stream ms){

		ByteArrayOutputStream b = new ByteArrayOutputStream();
		ObjectOutputStream o;
		try {
			o = new ObjectOutputStream(b);
			o.writeObject(ms);
		} catch (IOException e) {
			e.printStackTrace();
		}


		return ByteBuffer.wrap(b.toByteArray());

	}
	
	public static String serializeStream2(Stream ms){

		ByteArrayOutputStream b = new ByteArrayOutputStream();
		ObjectOutputStream o;
		try {
			o = new ObjectOutputStream(b);
			o.writeObject(ms);
		} catch (IOException e) {
			e.printStackTrace();
		}


		return Bytes.toHexString(b.toByteArray());

	}

	public static Stream deserializeStream(ByteBuffer buffer){

		Stream stream = null;

		byte[] bytes = new byte[buffer.remaining()];
		buffer.get(bytes, 0, bytes.length);

		ByteArrayInputStream b = new ByteArrayInputStream(bytes);
		ObjectInputStream o;
		try {
			o = new ObjectInputStream(b);
			stream = (Stream) o.readObject();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return stream;

	}

	public static Stream deserializeStream(byte[] bytes){

		Stream stream = null;

		ByteArrayInputStream b = new ByteArrayInputStream(bytes);
		ObjectInputStream o;
		try {
			o = new ObjectInputStream(b);
			stream = (Stream) o.readObject();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return stream;

	}


}

@@ -593,17 +593,16 @@
 ));%0A%0A%09%7D%0A
-%09
 %0A%09public
@@ -840,33 +840,32 @@
 ckTrace();%0A%09%09%7D%0A%0A
-%0A
 %09%09return Bytes.t
@@ -890,32 +890,33 @@
 eArray());%0A%0A%09%7D%0A%0A
+%0A
 %09public static S
@@ -943,25 +943,27 @@
 eam(
-ByteBuffer
+String
  buffer
+String
 )%7B%0A%0A
@@ -981,24 +981,81 @@
 ream = null;
+%0A%09%09ByteBuffer buffer = Bytes.fromHexString(bufferString);
 %0A%0A%09%09byte%5B%5D b
@@ -1434,392 +1434,7 @@
 %0A%0A%09%7D
-%0A%0A%09public static Stream deserializeStream(byte%5B%5D bytes)%7B%0A%0A%09%09Stream stream = null;%0A%0A%09%09ByteArrayInputStream b = new ByteArrayInputStream(bytes);%0A%09%09ObjectInputStream o;%0A%09%09try %7B%0A%09%09%09o = new ObjectInputStream(b);%0A%09%09%09stream = (Stream) o.readObject();%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D catch (ClassNotFoundException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return stream;%0A%0A%09%7D%0A%0A
 %0A%7D%0A

fix for deserialize fct