为什么';spring DefaultSerializer#serialize方法是否关闭ObjectOutputStream?
org.springframework.core.serializer.DefaultSerializer中的serialize方法没有关闭ObjectOutputStream,为什么为什么';spring DefaultSerializer#serialize方法是否关闭ObjectOutputStream?,spring,serialization,Spring,Serialization,org.springframework.core.serializer.DefaultSerializer中的serialize方法没有关闭ObjectOutputStream,为什么 public class DefaultSerializer implements Serializer<Object> { /** * Writes the source object to an output stream using Java Serialization. * The so
public class DefaultSerializer implements Serializer<Object> {
/**
* Writes the source object to an output stream using Java Serialization.
* The source object must implement {@link Serializable}.
*/
public void serialize(Object object, OutputStream outputStream) throws IOException {
if (!(object instanceof Serializable)) {
throw new IllegalArgumentException(getClass().getSimpleName() + " requires a Serializable payload " +
"but received an object of type [" + object.getClass().getName() + "]");
}
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
objectOutputStream.writeObject(object);
objectOutputStream.flush();
}
}
公共类DefaultSerializer实现序列化程序{
/**
*使用Java序列化将源对象写入输出流。
*源对象必须实现{@link Serializable}。
*/
公共void序列化(对象对象,OutputStream OutputStream)引发IOException{
if(!(可序列化的对象实例)){
抛出新的IllegalArgumentException(getClass()。getSimpleName()+“需要可序列化的负载”+
“但收到类型为[“+object.getClass().getName()+”]”的对象;
}
ObjectOutputStream ObjectOutputStream=新的ObjectOutputStream(outputStream);
objectOutputStream.writeObject(对象);
objectOutputStream.flush();
}
}