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 Object readFromFileAndDeserialize(String inFile) throws ClassNotFoundException, IOException {
    FileInputStream fin = new FileInputStream(inFile);
    ObjectInputStream ois = new ObjectInputStream(fin);
    Object oRead = ois.readObject();
    ois.close();//from  ww  w .  j  a  v a2s . com
    return oRead;
}

From source file:com.eviware.loadui.util.serialization.SerializationUtils.java

public static Object deserialize(byte[] serializedObject) throws IOException, ClassNotFoundException {
    if (serializedObject == null)
        return null;

    return new ObjectInputStream(new ByteArrayInputStream(serializedObject)).readObject();
}

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   w ww . j  a  v  a2 s.  c om*/
    try {
        gm = (GramModel) ois.readObject();
    } finally {
        IOUtils.closeQuietly(ois);
    }
    log.info("Deserialization of GramModel finished in {} ms", currentTimeMillis() - timeBefore);
    return gm;
}

From source file:javaslang.jackson.datatype.deserialize.SerializableDeserializer.java

@SuppressWarnings("unchecked")
private static <T> T deserialize(byte[] objectData) {
    try {/*  w w  w.  jav a 2 s .  com*/
        ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(objectData));
        return (T) stream.readObject();
    } catch (Exception x) {
        throw new IllegalStateException("Error deserializing object", x);
    }
}

From source file:gnomezgrave.gsyncj.auth.Profile.java

public static Profile loadProfileSettings(String fileName) throws IOException, ClassNotFoundException {
    ObjectInputStream oi = new ObjectInputStream(new FileInputStream(fileName));
    Profile profile = (Profile) oi.readObject();
    oi.close();/* w ww.  j  a  va 2  s  .  c o  m*/
    return profile;
}

From source file:IO.serializer.java

public static Object Deserialize(String objectFilename, boolean deleteSerialized) {
    String serializedFilename = String.format("%s\\%s.%s", m_systemTempDirectory, objectFilename,
            m_serializedFileExtension);//from   w w w . ja  v a2s.  co m
    Object serialized = null;

    if (Files.IsFile(serializedFilename)) {
        try (FileInputStream fin = new FileInputStream(serializedFilename)) {
            ObjectInputStream ois = new ObjectInputStream(fin);
            serialized = ois.readObject();
            ois.close();
        } catch (IOException | ClassNotFoundException ex) {
            Console.PrintLine(
                    String.format("Error deserilizing object '%s': %s", objectFilename, ex.getMessage()), true,
                    false);
        }
    }

    return serialized;
}

From source file:org.versly.rest.wsdoc.RestDocumentation.java

/**
 * Read and return a serialized {@link RestDocumentation} instance from <code>in</code>,
 * as serialized by {@link #toStream}./*from   w w  w .  j  a va  2 s.c  o m*/
 */
public static RestDocumentation fromStream(InputStream in) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(in);
        return (RestDocumentation) ois.readObject();
    } finally {
        if (ois != null)
            ois.close();
    }
}

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

public static MorphDictionaryImpl from(InputStream in, String srcLabel) throws Exception {
    log.info("About to deserialize MorphDictionary from InputStream of {}...", srcLabel);
    long timeBefore = currentTimeMillis();
    InputStream is = new BufferedInputStream(in, DICTIONARY_READING_BUFFER_SIZE);
    ObjectInputStream ois = new ObjectInputStream(is);
    MorphDictionaryImpl dict;// w  w  w.java  2s. c om
    try {
        // skip gram model
        @SuppressWarnings("unused")
        GramModel gm = (GramModel) ois.readObject();
        dict = (MorphDictionaryImpl) ois.readObject();
    } finally {
        IOUtils.closeQuietly(ois);
    }
    log.info("Deserialization of MorphDictionary finished in {} ms", currentTimeMillis() - timeBefore);
    return dict;
}

From source file:berlin.iconn.persistence.InOutOperations.java

public static float[][] loadSimpleWeights(File file) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath()));
    float[][] weights = (float[][]) ois.readObject();
    ois.close();//from  www.  j ava 2s  . c o m
    return weights;
}

From source file:license.rsa.WakeRSA.java

/**
 * ?// www  .  ja v a  2  s . co  m
 * 
 * @param keyFileName
 * @return
 * @throws Exception
 */
static PublicKey readPublicKeyFromFile() throws Exception {
    ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey));
    try {
        BigInteger m = (BigInteger) oin.readObject();
        BigInteger e = (BigInteger) oin.readObject();
        System.out.println();
        System.out.println();
        System.out.println("=======mmm=====" + m);
        System.out.println("=======eeee=====" + e);
        System.out.println();
        System.out.println();
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e);
        KeyFactory fact = KeyFactory.getInstance("RSA");
        return fact.generatePublic(keySpec);
    } finally {
        oin.close();
    }
}