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.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  .  jav a2  s.c  o  m*/

    Files.delete(file);

    return data;
}

From source file:Main.java

/**
 * This method deserializes an object from an input stream.
 *
 * @param file The input file/*from   w w  w  . j a v a  2  s  . c  o  m*/
 * @return The deserialized object
 * @exception IOException IOError
 */
public static Object deserializeObject(File file) throws IOException, ClassNotFoundException {
    FileInputStream fis = new FileInputStream(file);
    Object object = null;
    try {
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
        object = ois.readObject();
    } finally {
        fis.close();
    }
    return object;
}

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  w w .ja va 2  s .c  om*/
    return (T) object;
}

From source file:Main.java

/**
 * Redintegrate a serialized object.// www  . ja v a2s .c  o m
 * @param serial a byte array of the serialized object.
 * @return the original object or null if an error occurs.
 */
public static Object deserialize(byte[] serial) {
    ByteArrayInputStream bais = new ByteArrayInputStream(serial);
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(bais);
        return ois.readObject();
    } catch (IOException e) {
        return null;
    } catch (ClassNotFoundException e) {
        return null;
    } finally {
        try {
            if (ois != null)
                ois.close();
        } catch (IOException e) {
        }
    }
}

From source file:conceptnet.ConceptBuilder.java

public static Concept readConcept(String name) {
    Concept c = null;/*from  w  w  w . ja v  a2  s .co  m*/
    String path = conceptPath + name;
    File f = new File(path);
    if (!f.exists() || f.isDirectory()) {
        return null;
    }
    try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
        c = (Concept) (ois.readObject());
        ois.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return c;
}

From source file:com.alta189.deskbin.util.CryptUtils.java

private static boolean loadKey() {
    FileInputStream fis = null;//from w w  w .  jav a  2 s .c o  m
    ObjectInputStream in = null;
    try {
        fis = new FileInputStream(keyFile);
        in = new ObjectInputStream(fis);
        Object obj = in.readObject();
        if (obj != null && obj instanceof SecretKey) {
            key = (SecretKey) obj;
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(in);
    }
    return false;
}

From source file:de.kbs.acavis.service.SerializationHelper.java

public static PublicationIdentifier deserializePublicationIdentifier(String serialization)
        throws IOException, ClassNotFoundException {
    byte b[] = serialization.getBytes();

    ByteArrayInputStream bi = new ByteArrayInputStream(b);
    ObjectInputStream si = new ObjectInputStream(bi);

    PublicationIdentifier identifier = (PublicationIdentifier) si.readObject();

    si.close();/* w w  w. j  a  v  a 2s . c o  m*/
    bi.close();

    return identifier;
}

From source file:com.pcms.core.util.ObjectUtil.java

public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream bais = null;
    try {/*from w  ww. j av  a 2 s  .c om*/
        bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        return ois.readObject();
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    return null;
}

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

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

    Object obj = null;//w  ww. j  av a  2 s  .  co 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.mobicage.rogerthat.mfr.dal.Streamable.java

protected static Object fromBase64(String base64String) {
    try {/*ww  w  . j  a v  a2  s  .  co m*/
        ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(base64String));

        try {
            ZipInputStream zip = new ZipInputStream(bis);
            try {
                zip.getNextEntry();
                ObjectInput in = new ObjectInputStream(zip);
                try {
                    return in.readObject();
                } finally {
                    in.close();
                }
            } finally {
                zip.close();
            }
        } finally {
            bis.close();
        }
    } catch (ClassNotFoundException e) {
        log.log((Level.SEVERE), "ClassNotFoundException while deserializing member", e);
        return null;
    } catch (IOException e) {
        log.log((Level.SEVERE), "IOException while deserializing member", e);
        return null;
    }
}