Example usage for java.io ObjectInputStream ObjectInputStream

List of usage examples for java.io ObjectInputStream ObjectInputStream

Introduction

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

Prototype

public ObjectInputStream(InputStream in) throws IOException 

Source Link

Document

Creates an ObjectInputStream that reads from the specified InputStream.

Usage

From source file:com.mayalogy.mayu.io.LocalDataManager.java

public static ObjectInputStream openResourceAsObjectStream(final String resourceName) throws IOException {
    return new ObjectInputStream(openResourceAsInputStream(resourceName));
}

From source file:com.moz.fiji.hive.utils.FijiDataRequestSerializer.java

/**
 * Deserializes a data request./* w w w  . j  av a  2s  .  c om*/
 *
 * @param serialized A serialized data request.
 * @return A data request, or null if there is no data request in the given string.
 * @throws IOException If there is an IO error.
 */
public static FijiDataRequest deserialize(String serialized) throws IOException {
    final byte[] bytes = Base64.decodeBase64(serialized);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
    try {
        return (FijiDataRequest) ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(ois);
    }
}

From source file:com.ebay.erl.mobius.util.SerializableUtil.java

public static Object deserializeFromBase64(String base64String, Configuration conf) throws IOException {
    ObjectInputStream ois = null;
    try {// w w  w.j  a v a 2 s .co m
        byte[] objBinary = Base64.decodeBase64(base64String.getBytes());

        ois = new ObjectInputStream(new ByteArrayInputStream(objBinary));

        Object object = ois.readObject();

        if (conf != null) {
            if (object instanceof Configurable) {
                ((Configurable) object).setConf(conf);
            } else if (object instanceof Configurable[]) {
                Configurable[] confArray = (Configurable[]) object;
                for (Configurable aConfigurable : confArray) {
                    aConfigurable.setConf(conf);
                }
            }
        }

        return object;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        if (ois != null) {
            try {
                ois.close();
            } catch (Throwable e) {
            }
        }
    }
}

From source file:com.enonic.cms.core.portal.instruction.PostProcessInstruction.java

public final void deserialize(String value) throws IOException, ClassNotFoundException {
    ByteArrayInputStream in = new ByteArrayInputStream(Base64.decodeBase64(value.getBytes()));

    ObjectInputStream din = new ObjectInputStream(in);

    readExternal(din);//from   ww  w . ja  v  a 2  s  . co m

    in.close();
    din.close();
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.comments.pipeline.ExtendedMalletTopicModelEstimator.java

/**
 * Loads serialized vocabulary ({@code HashMap<String, Integer>}) from file
 *
 * @return vocabulary entries (key set)/*from   w w w.  j  av  a 2s .  com*/
 * @throws IOException
 * @throws ClassNotFoundException
 */
@SuppressWarnings("unchecked")
public static Set<String> readVocabulary(File vocabularyFile) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(vocabularyFile));
    Map<String, Integer> map = (Map<String, Integer>) ois.readObject();

    IOUtils.closeQuietly(ois);

    return map.keySet();
}

From source file:com.bworld.manager.ObjectSerializer.java

/**
 * Deserialize.//from  ww  w. j av  a 2  s . c om
 *
 * @param str the str
 * @return the object
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Object deserialize(String str) throws IOException {
    if (str == null || str.length() == 0)
        return null;
    try {
        ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
        ObjectInputStream objStream = new ObjectInputStream(serialObj);
        return objStream.readObject();
    } catch (Exception e) {
        //   throw WrappedIOException.wrap("Deserialization error: " + e.getMessage(), e);
    }
    return str;
}

From source file:io.cloudslang.content.httpclient.build.CookieStoreBuilder.java

public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream b = new ByteArrayInputStream(bytes);
    ObjectInputStream o = new ObjectInputStream(b);
    return o.readObject();
}

From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java

public static <T> T deserialize(byte[] serialized, Class<T> clazz) throws JobPersistenceException {
    // ToDO(keith): Serialize better than Java serialization.
    ByteArrayInputStream byteStream = new ByteArrayInputStream(serialized);
    try {/*from w  w w.j  a v  a  2 s .co  m*/
        ObjectInputStream objectStream = new ObjectInputStream(byteStream);
        Object deserialized = objectStream.readObject();
        objectStream.close();
        if (clazz.isInstance(deserialized)) {
            @SuppressWarnings("unchecked")
            T obj = (T) deserialized;
            return obj;
        }

        throw new JobPersistenceException("Deserialized object is not of the desired type");
    } catch (IOException | ClassNotFoundException e) {
        throw new JobPersistenceException("Could not deserialize.", e);
    }
}

From source file:com.servioticy.queueclient.SimpleQueueClient.java

LinkedList<Object> readQueue() throws ClassNotFoundException, IOException {
    LinkedList<Object> queue;
    try {//from  w  ww .  java  2  s  .com
        FileInputStream fileIn;
        fileIn = new FileInputStream(filePath);
        ObjectInputStream in = new ObjectInputStream(fileIn);
        queue = (LinkedList<Object>) in.readObject();
        in.close();
        fileIn.close();
    } catch (FileNotFoundException e) {
        queue = new LinkedList<Object>();
    }
    return queue;
}

From source file:com.tempescope.wunderground.WeatherLocationManager.java

public static WeatherLocationManager getManager(File file) {
    if (!file.exists()) {
        WeatherLocationManager manager = new WeatherLocationManager();
        manager.file = file;//w w  w . ja va 2s  . co m
        return manager;
    }
    try {
        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
        WeatherLocationManager manager = (WeatherLocationManager) in.readObject();
        in.close();
        manager.file = file;
        return manager;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}