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:com.splicemachine.derby.stream.output.insert.InsertTableWriterBuilder.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    isUpsert = in.readBoolean();/* w ww .  jav a  2  s  . c  om*/
    if (in.readBoolean())
        operationContext = (OperationContext) in.readObject();
    txn = SIDriver.driver().getOperationFactory().readTxn(in);
    pkCols = ArrayUtil.readIntArray(in);
    tableVersion = in.readUTF();
    execRowTypeFormatIds = ArrayUtil.readIntArray(in);
    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();
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *///from   w ww . jav  a  2  s  .c  om
public void testSerialization() {
    DefaultWindDataset d1 = new DefaultWindDataset();
    DefaultWindDataset 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 = (DefaultWindDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // try a dataset with some content...
    d1 = createSampleDataset1();
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

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

}

From source file:org.kepler.objectmanager.library.LibSearchConfiguration.java

private void init() {
    File saveFile = new File(_saveFileName);

    if (saveFile.exists()) {
        if (isDebugging) {
            log.debug("Save file exists: " + saveFile.toString());
        }//ww  w  .j  a  v  a2  s. c  o  m

        try {
            InputStream is = null;
            ObjectInput oi = null;
            try {
                is = new FileInputStream(saveFile);
                oi = new ObjectInputStream(is);
                Object newObj = oi.readObject();
                _searchTypes = (Vector<Integer>) newObj;
                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 save file: " + e1.getMessage());
            try {
                saveFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete save file: " + e2.getMessage());
            }
        }
    } else {
        setDefaults();
    }

}

From source file:org.lexgrid.valuesets.helper.compiler.FileSystemCachingValueSetDefinitionCompilerDecorator.java

/**
 * Retrieve coded node set./*  w ww.  j ava  2  s  . c  o m*/
 * 
 * @param md5 the md5
 * 
 * @return the coded node set
 * 
 * @throws Exception the exception
 */
protected CodedNodeSet retrieveCodedNodeSet(String md5) {

    try {

        File cachedCnsFile = new File(this.getDiskStorePath() + File.separator + this.getFileName(md5));
        if (!cachedCnsFile.exists()) {
            LoggerFactory.getLogger().info("Compiled Value Set Definition cache miss.");

            return null;
        } else {
            LoggerFactory.getLogger().info("Compiled Value Set Definition cache hit.");

            FileUtils.touch(cachedCnsFile);
        }

        ObjectInput in = new ObjectInputStream(new FileInputStream(cachedCnsFile));
        CodedNodeSetImpl cns;
        try {
            cns = (CodedNodeSetImpl) in.readObject();
        } catch (Exception e) {
            LoggerFactory.getLogger().warn(
                    "Compiled Value Set Definition was found, but it is invalid or corrupted. Removing...", e);
            if (!FileUtils.deleteQuietly(cachedCnsFile)) {
                FileUtils.forceDeleteOnExit(cachedCnsFile);
            }

            throw e;
        }

        in.close();

        if (cns == null) {
            return null;
        } else {
            return cns;
        }
    } catch (Exception e) {
        LoggerFactory.getLogger()
                .warn("There was an error retrieving the Compiled Value Set Definition from the Cache."
                        + " Caching will not be used for this Value Set Definition.", e);

        return null;
    }
}

From source file:de.pro.dbw.file.tipofthenight.api.TipOfTheNightModel.java

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

From source file:com.roche.iceboar.cachestorage.LocalCacheStorage.java

public CacheStatus loadCacheStatus(String cachePath) {
    InputStream file = null;//from  w  w w . j  a v a2 s  . c om
    InputStream buffer = null;
    ObjectInput input = null;
    try {
        file = new FileInputStream(cachePath);
        buffer = new BufferedInputStream(file);
        input = new ObjectInputStream(buffer);

        CacheStatus cacheStatus = (CacheStatus) input.readObject();
        return cacheStatus;
    } catch (Exception e) {
        System.out.println("Can't open file with cache settings. Expected file here: " + cachePath);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (buffer != null) {
            try {
                buffer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (file != null) {
            try {
                file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return new CacheStatus();
}

From source file:gridool.routing.strategy.ConsistentHash.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    HashFunction hashFunc = (HashFunction) in.readObject();
    this.hashFunction = hashFunc;
    this.numberOfVirtualNodes = in.readInt();
    this.circle = new TreeMap<Long, GridNode>();
    this.liveNodes = new TreeMap<GridNode, GridNode>(new NodeComparator(hashFunc));
    this.removedNodes = new HashMap<GridNode, GridNode>(32);
    final int numNodes = in.readInt();
    for (int i = 0; i < numNodes; i++) {
        GridNode node = (GridNode) in.readObject();
        add(node);/*from   www. j av a 2  s  . co  m*/
    }
    final int numRemoved = in.readInt();
    final Map<GridNode, GridNode> removedNodes = new HashMap<GridNode, GridNode>(numRemoved * 2);
    for (int i = 0; i < numRemoved; i++) {
        GridNode node = (GridNode) in.readObject();
        removedNodes.put(node, node);
    }
    this.removedNodes = removedNodes;
}

From source file:xbird.xquery.misc.BasicStringChunk.java

public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
    this._strPool = (List<String>) in.readObject();
    this._cchunks = (char[][]) in.readObject();
    this._cpointer = in.readLong();
}

From source file:org.kepler.gui.component.ShowFolders.java

/**
 * Load saved state/*from ww  w.j  a  v  a  2  s .  co  m*/
 */
private void init() {
    File saveFile = new File(_saveFileName);

    if (saveFile.exists()) {
        if (isDebugging) {
            log.debug("ShowFolders exists: " + saveFile.toString());
        }

        try {
            InputStream is = null;
            ObjectInput oi = null;
            try {
                is = new FileInputStream(saveFile);
                oi = new ObjectInputStream(is);
                Object newObj = oi.readObject();
                _showFolders = (Boolean) newObj;
                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 {
                saveFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete localSaveRepoFile: " + e2.getMessage());
            }
        }
    } else {
        // default to true
        set(true);
    }

}

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

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

    DefaultXYDataset d1 = new DefaultXYDataset();
    DefaultXYDataset 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 = (DefaultXYDataset) 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[][] data1 = new double[][] { x1, y1 };
    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 = (DefaultXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}