public class ConfigSerializer {
public IConfig cloneConfig(IConfig copiedConfigModel) {
IConfig copiedConfig = unwrap(copiedConfigModel);
IConfig copyConfig;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(copiedConfig);
byte[] buffer = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
copyConfig = (IConfig) objectInputStream.readObject();
}
catch (IOException e) {
// The streams work on the RAM, so an IOException should never happen.
e.printStackTrace();
copyConfig = null;
}
catch (ClassNotFoundException e) {
// This should never happen as well.
e.printStackTrace();
copyConfig = null;
}
IConfig resultModel = wrap(copyConfig);
return resultModel;
}