下面列出了java.io.Externalizable#readExternal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void externalize(final Externalizable original, final Externalizable copy) throws IOException, ClassNotFoundException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(baos);
original.writeExternal(out);
out.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final ObjectInputStream in = new ObjectInputStream(bais);
copy.readExternal(in);
}
@Override
public Externalizable read(Kryo kryo, Input input, Class<Externalizable> type) {
try {
Externalizable e = kryo.newInstance(type);
KryoObjectInput koi = new KryoObjectInput(input,kryo);
e.readExternal(koi);
return e;
} catch (IOException | ClassNotFoundException e1) {
throw new RuntimeException(e1);
}
}
public static void readObject(@Nonnull final InputStream is, @Nonnull final Externalizable dst)
throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(is);
dst.readExternal(ois);
}