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.apache.rahas.Token.java

/**
 * Implementing de-serialization logic in accordance with the serialization logic.
 * @param in Stream which used to read data.
 * @throws IOException If unable to de-serialize particular data member.
 * @throws ClassNotFoundException // w w  w.  j av  a  2s.c om
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    this.id = (String) in.readObject();

    this.state = in.readInt();

    String stringElement = (String) in.readObject();
    this.token = convertStringToOMElement(stringElement);

    stringElement = (String) in.readObject();
    this.previousToken = convertStringToOMElement(stringElement);

    stringElement = (String) in.readObject();
    this.attachedReference = convertStringToOMElement(stringElement);

    stringElement = (String) in.readObject();
    this.unattachedReference = convertStringToOMElement(stringElement);

    this.properties = (Properties) in.readObject();

    this.changed = in.readBoolean();

    // Read the length of the secret
    int secretLength = in.readInt();

    if (0 != secretLength) {
        byte[] buffer = new byte[secretLength];
        if (secretLength != in.read(buffer)) {
            throw new IllegalStateException("Bytes read from the secret key is not equal to serialized length");
        }
        this.secret = buffer;
    } else {
        this.secret = null;
    }

    this.created = (Date) in.readObject();

    this.expires = (Date) in.readObject();

    this.issuerAddress = (String) in.readObject();

    this.encrKeySha1Value = (String) in.readObject();
}

From source file:org.buzzjoe.SimpleDataStorage.SimpleDataStorage.java

/**
 * Returns properties value out of this.data container.
 * /*from   w  ww  .j a v a 2 s. c  o m*/
 * @param propertyName Property to get  
 * @return a string containing the value of requestet proprety 
 */
public Object get(String propertyName) {

    String data = this.data.getProperty(propertyName);

    try {
        int integer = Integer.parseInt(data);
        // Looks like we've got an Integer value. Return it.
        return integer;
    } catch (NumberFormatException nFE) {
        // whooops. This wasn't integer. Let's try if we can deserialize...
        try {

            byte[] decoded = Base64.decodeBase64(data);

            ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(decoded));
            Object oData = in.readObject();
            in.close();

            return oData;

        } catch (Exception e) {
            // Nope. Not even serialized stuff. So it must be a string
            return data;
        }
    }
}

From source file:xbird.xquery.dm.value.sequence.MarshalledSequence.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    final Type type = (Type) in.readObject();
    this._type = type;
    final boolean redirectable = in.readBoolean();
    if (redirectable) {
        this._redirectable = true;
        this._entity = (Sequence<Item>) in.readObject();
    } else {/*  ww w.  j  a  va 2s. co  m*/
        this._redirectable = false; // just for readability
        final boolean isDecodedSeq = in.readBoolean();
        if (isDecodedSeq) {
            IncrDecodedSequnece entity = IncrDecodedSequnece.readFrom(in);
            entity._type = type;
            this._entity = entity;
        } else {
            final boolean piped = in.readBoolean();
            final XQEventDecoder decoder;
            if (piped) {
                this._piped = true;
                decoder = pipedIn(in, _reaccessable);
            } else {
                this._piped = false;
                decoder = bulkIn(in); // This is required for nested Object serialization/deserialization                    
            }
            if (DEBUG_DESER_SPEED) {
                try {
                    this._entity = decoder.decode();
                } catch (XQueryException e) {
                    throw new IllegalStateException("failed decoding", e);
                }
            } else {
                final IncrDecodedSequnece entity = new IncrDecodedSequnece(decoder, type);
                entity._piped = piped;
                this._entity = entity;
            }
        }
    }
}

From source file:org.kepler.objectmanager.repository.RepositoryManager.java

/**
 * First we check to see if there is a configuration file containing the
 * name of the default remote save repository. Then we check the
 * configuration file./*  w  w w .  j  ava2s.co  m*/
 */
private void initRemoteSaveRepo() {
    if (isDebugging)
        log.debug("initRemoteSaveRepo()");
    File remoteSaveRepoFile = new File(_remoteSaveRepoFileName);

    if (!remoteSaveRepoFile.exists()) {
        setSaveRepository(null);
    } else {
        if (isDebugging) {
            log.debug("remoteSaveRepo exists: " + remoteSaveRepoFile.toString());
        }

        try {
            InputStream is = null;
            ObjectInput oi = null;
            try {
                is = new FileInputStream(remoteSaveRepoFile);
                oi = new ObjectInputStream(is);
                Object newObj = oi.readObject();

                String repoName = (String) newObj;
                Repository saveRepo = getRepository(repoName);
                if (saveRepo != null) {
                    setSaveRepository(saveRepo);
                }

                return;

            } finally {
                if (oi != null) {
                    oi.close();
                }
                if (is != null) {
                    is.close();
                }
            }

        } catch (Exception e1) {
            // problem reading file, try to delete it
            log.warn("Exception while reading localSaveRepoFile: " + e1.getMessage());
            try {
                remoteSaveRepoFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete localSaveRepoFile: " + e2.getMessage());
            }
        }
    }

}

From source file:org.openspaces.remoting.ExecutorRemotingTask.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    lookupName = in.readUTF();/*  w  ww .j  a v  a 2 s.  c  om*/
    methodName = in.readUTF();
    int size = in.readInt();
    if (size > 0) {
        arguments = new Object[size];
        for (int i = 0; i < size; i++) {
            arguments[i] = in.readObject();
        }
    }
    size = in.readInt();
    if (size > 0) {
        metaArguments = new Object[size];
        for (int i = 0; i < size; i++) {
            metaArguments[i] = in.readObject();
        }
    }

    methodHash = new RemotingUtils.MethodHash();
    methodHash.readExternal(in);
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///w w w .j  ava 2s  .  c  om
public void testSerialization() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("Key 1", new Double(23));
    v1.addValue("Key 2", null);
    v1.addValue("Key 3", new Double(42));
    DefaultKeyedValues v2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(v1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        v2 = (DefaultKeyedValues) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(v1, v2);
}

From source file:info.magnolia.cms.core.version.BaseVersionManager.java

/**
 * Get Rule used for this version./*www  . ja  v  a2  s . c o  m*/
 * @param versionedNode
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws RepositoryException
 */
protected Rule getUsedFilter(Node versionedNode)
        throws IOException, ClassNotFoundException, RepositoryException {
    // if restored, update original node with the restored node and its subtree
    ByteArrayInputStream inStream = null;
    try {
        String ruleString = this.getSystemNode(versionedNode).getProperty(PROPERTY_RULE).getString();
        inStream = new ByteArrayInputStream(Base64.decodeBase64(ruleString.getBytes()));
        ObjectInput objectInput = new ObjectInputStream(inStream);
        return (Rule) objectInput.readObject();
    } catch (IOException e) {
        throw e;
    } catch (ClassNotFoundException e) {
        throw e;
    } finally {
        IOUtils.closeQuietly(inStream);
    }
}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from   w  w w.j  a v a 2 s .co  m*/
public void testSerialization() {

    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("Key 1", "Object 1");
    ko1.addObject("Key 2", null);
    ko1.addObject("Key 3", "Object 2");

    KeyedObjects ko2 = null;

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

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        ko2 = (KeyedObjects) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(ko1, ko2);

}

From source file:uk.co.revsys.content.repository.cloud.CloudCacheStore.java

@Override
protected void fromStreamLockSafe(ObjectInput objectInput) throws CacheLoaderException {
    String source;/*from   w  ww.j  a v a2 s .  c o  m*/
    try {
        source = (String) objectInput.readObject();
    } catch (Exception e) {
        throw convertToCacheLoaderException("Error while reading from stream", e);
    }
    if (containerName.equals(source)) {
        log.attemptToLoadSameBucketIgnored(source);
    } else {
        // TODO implement stream handling. What's the JClouds API to "copy" one bucket to another?
    }
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java

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

    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("Key 1", new Double(23));
    v1.addValue("Key 2", null);
    v1.addValue("Key 3", new Double(42));

    DefaultKeyedValues v2 = null;

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

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

}