Example usage for java.io ObjectInputStream readObject

List of usage examples for java.io ObjectInputStream readObject

Introduction

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

Prototype

public final Object readObject() throws IOException, ClassNotFoundException 

Source Link

Document

Read an object from the ObjectInputStream.

Usage

From source file:com.antbrains.crf.hadoop.InstanceGenerator.java

public static Object string2Object(String s) throws IOException, ClassNotFoundException {
    byte b[] = s.getBytes("UTF8");
    byte[] bytes = Base64.decodeBase64(b);
    ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
    ObjectInputStream si = new ObjectInputStream(bi);
    return si.readObject();
}

From source file:com.evolveum.midpoint.util.SerializationUtil.java

public static <T> T fromString(String string) throws IOException, ClassNotFoundException {
    byte[] data = Base64.decodeBase64(string);
    ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data));
    Object object = objectInputStream.readObject();
    objectInputStream.close();/*from w ww.ja va  2  s  . co m*/
    return (T) object;
}

From source file:homemade.apps.framework.homerlibs.utils.ObjectSerializer.java

public static Object deserialize(String str) {
    if (str == null || str.length() == 0)
        return null;
    try {// w w w  .j  a  va2  s .c o  m
        ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
        ObjectInputStream objStream = new ObjectInputStream(serialObj);
        return objStream.readObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mErrorReturn;
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.util.SerializationUtils.java

/**
 * Deserializes an object from disk.//from  w w w  .ja v  a 2s.c o  m
 *
 * @param filePath the file path
 * @return an object. Clients have to cast the object to the expected type.
 * @throws Exception an exception
 */
public static Object deserializeFromDisk(String filePath) throws Exception {
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(filePath)));

    return in.readObject();
}

From source file:id.co.nlp.MachineTranslation.Utils.Util.java

public static Object deserializing(String pathfile)
        throws FileNotFoundException, IOException, ClassNotFoundException {
    FileInputStream fileIn = new FileInputStream(pathfile);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Object object = in.readObject();
    in.close();/*w  w w  .j a v  a2s. co m*/
    fileIn.close();
    return object;
}

From source file:com.yfiton.oauth.OAuthUtils.java

public static AuthorizationData readAuthorizationInfo(Path file)
        throws ConfigurationException, IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file));
    AuthorizationData data = (AuthorizationData) ois.readObject();
    ois.close();//from  w  ww  . j  av a2s .  c o  m

    Files.delete(file);

    return data;
}

From source file:net.dontdrinkandroot.utils.lang.SerializationUtils.java

@SuppressWarnings("unchecked")
public static <T extends Serializable> T fastClone(T object) {

    Object obj = null;//  w w  w . j a  v a2s  . c  o  m
    try {

        /* Write the object out to a byte array */
        FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(fbos);
        out.writeObject(object);
        out.flush();
        out.close();

        /* Retrieve an input stream from the byte array and read a copy of the object back in. */
        ObjectInputStream in = new ObjectInputStream(fbos.getInputStream());
        obj = in.readObject();

    } catch (IOException e) {
        throw new SerializationException(e);
    } catch (ClassNotFoundException cnfe) {
        throw new SerializationException(cnfe);
    }

    return (T) obj;
}

From source file:com.textocat.textokit.morph.opencorpora.resource.GramModelDeserializer.java

public static GramModel from(InputStream in, String srcLabel) throws Exception {
    log.info("About to deserialize GramModel from InputStream of {}...", srcLabel);
    long timeBefore = currentTimeMillis();
    InputStream is = new BufferedInputStream(in);
    ObjectInputStream ois = new ObjectInputStream(is);
    GramModel gm;//from   www  .ja v  a  2  s.  c o m
    try {
        gm = (GramModel) ois.readObject();
    } finally {
        IOUtils.closeQuietly(ois);
    }
    log.info("Deserialization of GramModel finished in {} ms", currentTimeMillis() - timeBefore);
    return gm;
}

From source file:Main.java

public static <T> List<T> deepCopy(List<T> src) {
    try {/*from  w  w w. j  a v a 2 s  .  c om*/
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);

        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        @SuppressWarnings("unchecked")
        List<T> dest = (List<T>) in.readObject();
        return dest;
    } catch (Exception e) {
        return null;
    }
}

From source file:gui.CompressDecompress.java

private static List<List<BigInteger>> deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream b = new ByteArrayInputStream(bytes);
    ObjectInputStream o = new ObjectInputStream(b);
    return (List<List<BigInteger>>) o.readObject();
}