Example usage for java.io ObjectInput readObject

List of usage examples for java.io ObjectInput readObject

Introduction

In this page you can find the example usage for java.io ObjectInput readObject.

Prototype

public Object readObject() throws ClassNotFoundException, IOException;

Source Link

Document

Read and return an object.

Usage

From source file:org.jfree.data.xy.junit.DefaultXYZDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*www  . j a  v  a  2  s .c  om*/
public void testSerialization() {

    DefaultXYZDataset d1 = new DefaultXYZDataset();
    DefaultXYZDataset d2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultXYZDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // try a dataset with some content...
    double[] x1 = new double[] { 1.0, 2.0, 3.0 };
    double[] y1 = new double[] { 4.0, 5.0, 6.0 };
    double[] z1 = new double[] { 7.0, 8.0, 9.0 };
    double[][] data1 = new double[][] { x1, y1, z1 };
    d1.addSeries("S1", data1);
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultXYZDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

From source file:com.splicemachine.derby.stream.function.RowAndIndexGenerator.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    heapConglom = in.readLong();//from   w  ww  . j a  v a 2s .co m
    if (in.readBoolean())
        operationContext = (OperationContext) in.readObject();
    txn = SIDriver.driver().getOperationFactory().readTxn(in);
    pkCols = ArrayUtil.readIntArray(in);
    tableVersion = in.readUTF();
    execRowDefinition = (ExecRow) in.readObject();
    autoIncrementRowLocationArray = new RowLocation[in.readInt()];
    for (int i = 0; i < autoIncrementRowLocationArray.length; i++)
        autoIncrementRowLocationArray[i] = (RowLocation) in.readObject();
    spliceSequences = new SpliceSequence[in.readInt()];
    for (int i = 0; i < spliceSequences.length; i++)
        spliceSequences[i] = (SpliceSequence) in.readObject();
    heapConglom = in.readLong();
    int iSize = in.readInt();
    tentativeIndices = new ArrayList<>(iSize);
    for (int i = 0; i < iSize; i++) {
        byte[] message = new byte[in.readInt()];
        in.readFully(message);
        tentativeIndices.add(DDLMessage.TentativeIndex.parseFrom(message));
    }
}

From source file:com.github.naoghuman.cm.model.matrix.MatrixModel.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.setId(in.readLong());
    this.setGenerationTime(in.readLong());
    this.setTitle(StringEscapeUtils.unescapeHtml4(String.valueOf(in.readObject())));
    this.setDescription(StringEscapeUtils.unescapeHtml4(String.valueOf(in.readObject())));
}

From source file:org.ejbca.core.model.approval.approvalrequests.EditEndEntityApprovalRequest.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    int version = in.readInt();
    if (version == 1) {
        newuserdata = (EndEntityInformation) in.readObject();
        clearpwd = in.readBoolean();//ww  w .  j a  v a2  s.  c om
        orguserdata = (EndEntityInformation) in.readObject();
    }
}

From source file:org.lunarray.model.descriptor.model.extension.impl.ExtensionContainerImpl.java

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*  w  ww .j  av  a2 s .com*/
public void readExternal(final ObjectInput input) throws IOException, ClassNotFoundException {
    Validate.notNull(input, "Input stream may not be null.");
    this.initialized = false;
    this.extensionReferences = (Map<Class<? extends Extension>, ExtensionRef<? extends Extension>>) input
            .readObject();
}

From source file:BinaryHeapQueue.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    comparator = (Comparator) in.readObject();
    elements = (Queueable[]) in.readObject();
    size = in.readInt();// w  w w  .j  a va2  s  .  c  o  m
}

From source file:net.openhft.chronicle.wire.benchmarks.Data.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    setPrice(in.readDouble());//w  ww  .  j  a v  a  2 s . c  o m
    setLongInt(in.readLong());
    setSmallInt(in.readInt());
    setFlag(in.readBoolean());
    setSide((Side) in.readObject());
    setText((String) in.readObject());
}

From source file:org.jfree.data.xy.junit.TableXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 */// w ww.j ava2s  .co  m
public void testSerialization() {

    DefaultTableXYDataset d1 = new DefaultTableXYDataset();
    d1.addSeries(createSeries2());
    DefaultTableXYDataset d2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultTableXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(d1, d2);

}

From source file:com.aol.advertising.qiao.util.cache.ValueWrapper.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.insertionTime = in.readLong();
    this.lastAccessTime = in.readLong();
    this.timeout = in.readInt();
    this.isModified = in.readByte();
    this.value = (V) in.readObject();
}

From source file:org.apache.synapse.message.store.impl.rabbitmq.RabbitMQConsumer.java

public MessageContext receive() {
    if (!checkConnection()) {
        if (!reconnect()) {
            if (logger.isDebugEnabled()) {
                logger.debug(getId() + " cannot receive message from store. Can not reconnect.");
            }//from w w  w  . j  ava2  s.c  o  m
            return null;
        } else {
            logger.info(getId() + " reconnected to store.");
            isReceiveError = false;
        }
    }
    //setting channel
    if (channel != null) {
        if (!channel.isOpen()) {
            if (!setChannel()) {
                logger.info(getId() + " unable to create the channel.");
                return null;
            }
        }
    } else {
        if (!setChannel()) {
            logger.info(getId() + " unable to create the channel.");
            return null;
        }
    }
    //receive messages
    try {

        GetResponse delivery = null;
        delivery = channel.basicGet(queueName, false);

        if (delivery != null) {
            //deserilizing message
            StorableMessage storableMessage = null;
            ByteArrayInputStream bis = new ByteArrayInputStream(delivery.getBody());
            ObjectInput in = new ObjectInputStream(bis);
            try {
                storableMessage = (StorableMessage) in.readObject();
            } catch (ClassNotFoundException e) {
                logger.error(getId() + "unable to read the stored message" + e);
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            }

            bis.close();
            in.close();
            org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc();
            MessageContext synapseMc = store.newSynapseMc(axis2Mc);
            synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc);
            updateCache(delivery, synapseMc, null, false);
            if (logger.isDebugEnabled()) {
                logger.debug(getId() + " Received MessageId:" + delivery.getProps().getMessageId());
            }
            return synapseMc;
        }
    } catch (ShutdownSignalException sse) {
        logger.error(getId() + " connection error when receiving messages" + sse);
    } catch (IOException ioe) {
        logger.error(getId() + " connection error when receiving messages" + ioe);
    }
    return null;
}