Java Code Examples for java.io.Externalizable.readExternal()

The following are Jave code examples for showing how to use readExternal() of the java.io.Externalizable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javify   File: CommandInfo.java   View Source Code Vote up 7 votes
/**
 * 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;
}
 
Example 2
Project: jvm-stm   File: CommandInfo.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: JamVM-PH   File: CommandInfo.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 4
Project: classpath   File: CommandInfo.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 5
Project: triplea   File: Decoder.java   View Source Code Vote up 5 votes
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);
}
 
Example 6
Project: tomee   File: JndiRequestTest.java   View Source Code Vote up 5 votes
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);
}
 
Example 7
Project: spliceengine   File: ExternalizableSerializer.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 8
Project: incubator-hivemall   File: ObjectUtils.java   View Source Code Vote up 4 votes
public static void readObject(@Nonnull final InputStream is, @Nonnull final Externalizable dst)
        throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(is);
    dst.readExternal(ois);
}