package net.yyc.common.rabbitmq.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

/**
 * 反序列化时将旧包名 BaseMap 映射到 classpath 中的兼容类。
 */
class CompatibleObjectInputStream extends ObjectInputStream {

	CompatibleObjectInputStream(InputStream in) throws IOException {
		super(in);
	}

	private static final String LEGACY_BASE_MAP_CLASS = "com.qunzhixinxi.hnqz.common.core.entity.BaseMap";

	@Override
	protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
		ObjectStreamClass streamDesc = super.readClassDescriptor();
		if (LEGACY_BASE_MAP_CLASS.equals(streamDesc.getName())) {
			return ObjectStreamClass.lookup(com.qunzhixinxi.hnqz.common.core.entity.BaseMap.class);
		}
		return streamDesc;
	}

	@Override
	protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
		if (LEGACY_BASE_MAP_CLASS.equals(desc.getName())) {
			return com.qunzhixinxi.hnqz.common.core.entity.BaseMap.class;
		}
		return super.resolveClass(desc);
	}
}
