本文整理汇总了Java中java.io.Externalizable.readExternal方法的典型用法代码示例。如果您正苦于以下问题:Java Externalizable.readExternal方法的具体用法?Java Externalizable.readExternal怎么用?Java Externalizable.readExternal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.Externalizable
的用法示例。
在下文中一共展示了Externalizable.readExternal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommandObject
import java.io.Externalizable; //导入方法依赖的package包/类
/**
* Returns the instantiated bean.
* If the bean implements <code>CommandObject</code>, its
* <code>setCommandContext</code> method will be called.
* @param dh the data handler describing the command data
* @param loader the class loader used to instantiate the bean
*/
public Object getCommandObject(DataHandler dh, ClassLoader loader)
throws IOException, ClassNotFoundException
{
Object object = Beans.instantiate(loader, className);
if (object != null)
{
if (object instanceof CommandObject)
{
CommandObject command = (CommandObject)object;
command.setCommandContext(verb, dh);
}
else if (dh != null && (object instanceof Externalizable))
{
InputStream in = dh.getInputStream();
if (in != null)
{
Externalizable externalizable = (Externalizable)object;
externalizable.readExternal(new ObjectInputStream(in));
}
}
}
return object;
}
示例2: readMessageHeader
import java.io.Externalizable; //导入方法依赖的package包/类
private MessageHeader readMessageHeader(final SocketChannel channel, final ObjectInputStream objectInput)
throws IOException, ClassNotFoundException {
final INode to;
if (objectInput.read() == 1) {
to = null;
} else {
if (objectInput.read() == 1) {
// this may be null if we
// have not yet fully joined the network
to = nioSocket.getLocalNode();
} else {
to = new Node();
((Node) to).readExternal(objectInput);
}
}
final INode from;
final int readMark = objectInput.read();
if (readMark == 1) {
from = nioSocket.getRemoteNode(channel);
} else if (readMark == 2) {
from = null;
} else {
from = new Node();
((Node) from).readExternal(objectInput);
}
final Serializable message;
final byte type = (byte) objectInput.read();
if (type != Byte.MAX_VALUE) {
final Externalizable template = getTemplate(type);
template.readExternal(objectInput);
message = template;
} else {
message = (Serializable) objectInput.readObject();
}
return new MessageHeader(to, from, message);
}
示例3: externalize
import java.io.Externalizable; //导入方法依赖的package包/类
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);
}
示例4: read
import java.io.Externalizable; //导入方法依赖的package包/类
@Override
public Externalizable read(Kryo kryo, Input input, Class<Externalizable> type) {
try {
Externalizable e = type.newInstance();
KryoObjectInput koi = new KryoObjectInput(input,kryo);
e.readExternal(koi);
return e;
} catch (IOException | ClassNotFoundException | IllegalAccessException | InstantiationException e1) {
throw new RuntimeException(e1);
}
}
示例5: readObject
import java.io.Externalizable; //导入方法依赖的package包/类
public static void readObject(@Nonnull final InputStream is, @Nonnull final Externalizable dst)
throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(is);
dst.readExternal(ois);
}