/*
 * Copyright 1999-2010 Luca Garulli (l.garulli--at--orientechnologies.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.orientechnologies.orient.core.serialization.serializer.stream;

import java.io.IOException;

import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.core.serialization.OBinaryProtocol;
import com.orientechnologies.orient.core.serialization.serializer.string.OStringSerializerAnyRuntime;

/**
 * Delegates to the OStringSerializerAnyRuntime class but transform to/from bytes.
 * 
 * @see OStringSerializerAnyRuntime
 * @author Luca Garulli
 * 
 */
public class OStreamSerializerAnyRuntime implements OStreamSerializer {
	private static final String											NAME			= "au";
	public static final OStreamSerializerAnyRuntime	INSTANCE	= new OStreamSerializerAnyRuntime();

	public String getName() {
		return NAME;
	}

	/**
	 * Re-Create any object if the class has a public constructor that accepts a String as unique parameter.
	 */
	public Object fromStream(final ODatabaseRecord<?> iDatabase, final byte[] iStream) throws IOException {
		if (iStream == null || iStream.length == 0)
			// NULL VALUE
			return null;

		return OStringSerializerAnyRuntime.INSTANCE.fromStream(iDatabase, OBinaryProtocol.bytes2string(iStream));
	}

	public byte[] toStream(final ODatabaseRecord<?> iDatabase, final Object iObject) throws IOException {
		if (iObject == null)
			return new byte[0];

		return OBinaryProtocol.string2bytes(OStringSerializerAnyRuntime.INSTANCE.toStream(iDatabase, iObject));
	}
}

@@ -741,27 +741,175 @@
 java.io.
-IOException
+ByteArrayInputStream;%0D%0Aimport java.io.ByteArrayOutputStream;%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.ObjectInputStream;%0D%0Aimport java.io.ObjectOutputStream
 ;%0D%0A%0D%0Aimp
@@ -1019,37 +1019,41 @@
 ore.
-serialization.OBinaryProtocol
+exception.OSerializationException
 ;%0D%0Ai
@@ -1168,86 +1168,35 @@
 %0A * 
-Delegates to the OStringSerializerAnyRuntime class but transform to/from bytes
+Uses the Java serialization
 .%0D%0A 
@@ -1862,378 +1862,707 @@
 %0D%0A%09%09
-return OStringSerializerAnyRuntime.INSTANCE.fromStream(iDatabase, OBinaryProtocol.bytes2string(iStream));%0D%0A%09%7D%0D%0A%0D%0A%09public byte%5B%5D toStream(final ODatabaseRecord%3C?%3E iDatabase, final Object iObject) throws IOException %7B%0D%0A%09%09if (iObject == null)%0D%0A%09%09%09return new byte%5B0%5D;%0D%0A%0D%0A%09%09return OBinaryProtocol.string2bytes(OStringSerializerAnyRuntime.INSTANCE.toStream(iDatabase, iObject)
+final ByteArrayInputStream is = new ByteArrayInputStream(iStream);%0D%0A%09%09final ObjectInputStream in = new ObjectInputStream(is);%0D%0A%09%09try %7B%0D%0A%09%09%09return in.readObject();%0D%0A%09%09%7D catch (ClassNotFoundException e) %7B%0D%0A%09%09%09throw new OSerializationException(%22Can't unmarshall Java serialized object%22, e);%0D%0A%09%09%7D finally %7B%0D%0A%09%09%09in.close();%0D%0A%09%09%09is.close();%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public byte%5B%5D toStream(final ODatabaseRecord%3C?%3E iDatabase, final Object iObject) throws IOException %7B%0D%0A%09%09if (iObject == null)%0D%0A%09%09%09return new byte%5B0%5D;%0D%0A%0D%0A%09%09final ByteArrayOutputStream os = new ByteArrayOutputStream();%0D%0A%09%09final ObjectOutputStream oos = new ObjectOutputStream(os);%0D%0A%09%09oos.writeObject(iObject);%0D%0A%09%09oos.close();%0D%0A%0D%0A%09%09return os.toByteArray(
 );%0D%0A

Used Java serialization in place of string serialization.