Hey Guys.
We just stumbled over an unimplemented method and made it work. Here is the code, if you want to use it. I will check if there are questions
[java]package com.jme3.network.serializing.serializers;
import com.jme3.network.serializing.Serializer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
-
Serializes uses Java built-in method.
-
@author Agares
*/
@SuppressWarnings(“unchecked”)
public class SerializableSerializer extends Serializer {@Override
public Serializable readObject(ByteBuffer data, Class c) throws IOException {
byte[] buf = data.array();
ByteArrayInputStream bis = new ByteArrayInputStream(buf);
ObjectInputStream ois = new ObjectInputStream(bis);
ois.close();
bis.close();
try {
return (Serializable) ois.readObject();
} catch (ClassNotFoundException ex) {
Logger.getLogger(SerializableSerializer.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}@Override
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
if (object instanceof Serializable){
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(object);
oos.flush();
oos.close();
bos.close();
byte[] byteArr = bos.toByteArray();
buffer.put(byteArr);
}
}
}[/java]
regards,
Tirnithil