本文整理匯總了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);
}