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:Main.java

public static Object deSerialization(String str) throws IOException, ClassNotFoundException {
    byte[] mobileBytes = Base64.decode(str.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    Object object = (Object) objectInputStream.readObject();
    objectInputStream.close();// w w  w.j  a  va2s.  c om

    return object;
}

From source file:Main.java

public static <T> List<T> readList(String root, String filename, Class<T> type) {
    List<T> objects = new ArrayList<>();
    File file = new File(root, filename);
    try {// w w  w .ja  v  a 2  s.co  m
        if (file.exists()) {
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Object object = ois.readObject();
            if (object instanceof List) {
                for (Object it : (List) object) {
                    objects.add(type.cast(it));
                }
            }
            ois.close();
            return Collections.unmodifiableList(objects);
        }
    } catch (Exception e) {
        Log.e(TAG, String.format("Failed to read [%s]", file), e);
    }
    return Collections.emptyList();
}

From source file:Main.java

public static List String2SceneList(String SceneListString) throws IOException, ClassNotFoundException {

    byte[] mobileBytes = Base64.decode(SceneListString.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    List SceneList = (List) objectInputStream.readObject();
    objectInputStream.close();//www .  j a v  a2s  .c  o m

    return SceneList;
}

From source file:Main.java

public static Object deserializeObject(byte[] b) {
    try {//from   w w w.ja v a 2  s  .  c  om
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
        Object object = in.readObject();
        in.close();

        return object;
    } catch (ClassNotFoundException cnfe) {
        //         Log.e("deserializeObject", "class not found error", cnfe);

        return null;
    } catch (IOException ioe) {
        //         Log.e("deserializeObject", "io error", ioe);

        return null;
    }
}

From source file:Main.java

public static Object deserializeObject(byte[] b) {
    try {//from www.j  a  v  a  2  s . c  om
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
        Object object = in.readObject();
        in.close();

        return object;
    } catch (ClassNotFoundException cnfe) {
        Log.e("deserializeObject", "class not found error", cnfe);

        return null;
    } catch (IOException ioe) {
        Log.e("deserializeObject", "io error", ioe);

        return null;
    }
}

From source file:Main.java

/**
 * This method deserializes an object from an input stream.
 *
 * @param file The input file//from   w w  w .  jav  a 2  s.co 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.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();//w w w. ja v a  2 s  . c  om
    return oRead;
}

From source file:Main.java

public static Object readSerializableObjectFromFile(FileInputStream fileIn) {
    Object b = null;// ww w  .ja v a2s  .c  om
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(fileIn);
        b = in.readObject();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return b;
}

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 ww  .j  ava 2  s .  c  o  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:com.mayalogy.mayu.io.LocalDataManager.java

public static Object readFromJarAndDeserialize(String resourceName) throws ClassNotFoundException, IOException {
    InputStream is = Class.class.getResourceAsStream("/" + resourceName);
    if (is == null) { //Used for when jar is running in a servlet
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        is = classLoader.getResourceAsStream(resourceName);
    }//w w  w  .  jav  a 2 s. c  om
    ObjectInputStream ois = new ObjectInputStream(is);
    Object oRead = ois.readObject();
    ois.close();
    return oRead;
}