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

public static Object restore(String fileName) throws IOException, ClassNotFoundException {
    FileInputStream fis = new FileInputStream(fileName);
    ObjectInputStream in = new ObjectInputStream(fis);
    Object obj = in.readObject();
    in.close();/*w ww .  j av a 2  s .co  m*/
    return obj;
}

From source file:Main.java

public static Object readObject(InputStream o) throws IOException, ClassNotFoundException {
    ObjectInputStream oo = new ObjectInputStream(o);
    try {//from w w  w.  j a  v  a  2 s.  com
        return oo.readObject();
    } finally {
        oo.close();
    }
}

From source file:Main.java

public static Object StringToObject(String str) throws Exception {
    byte[] data = Base64.decode(str, 0);
    ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data));
    Object object = objectInputStream.readObject();
    objectInputStream.close();/*from www .j  a  va  2s.c o m*/
    return object;
}

From source file:Main.java

public static Object DeserializeObject(String path) throws ClassNotFoundException, IOException {
    Object o;//from  w w w .  ja  va 2s  . c om
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(path)));
    o = ois.readObject();
    return o;
}

From source file:Main.java

public static Object stm2obj(InputStream f) throws IOException, ClassNotFoundException {
    ObjectInputStream oo = new ObjectInputStream(f);
    try {//w  ww.j a  va  2 s.  com
        return oo.readObject();
    } finally {
        oo.close();
    }
}

From source file:Main.java

public static Object deserializeObject(byte[] b) {
    try {//from   ww w  .  j  av a 2  s  .c  o m
        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 <T> T deserializeObjectFromFile(FileInputStream input) {
    try {/*from  www .j  ava  2  s  .  c  o  m*/
        ObjectInputStream deserializer = new ObjectInputStream(input);
        return (T) deserializer.readObject();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static Object fromByteArray(byte[] inputBytes) {
    Object obj = null;/*w w  w  .ja v  a 2 s . c  o  m*/
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputBytes);
    ObjectInput objIn = null;
    try {
        objIn = new ObjectInputStream(byteArrayInputStream);
        obj = objIn.readObject();
    } catch (java.io.IOException ioe) {
        return null;
    } catch (java.lang.ClassNotFoundException cnfe) {
        return null;
    } finally {
        try {
            byteArrayInputStream.close();
            objIn.close();
        } catch (java.io.IOException closeIOE) {

        }
    }
    return obj;
}

From source file:Main.java

public static Object stringToObject(String encodedObject) {
    try {/*ww  w  .java 2 s .c  om*/
        return new ObjectInputStream(
                new Base64InputStream(new ByteArrayInputStream(encodedObject.getBytes()), Base64.DEFAULT))
                        .readObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Object deserializable(byte[] bytes) {
    Object obj = null;//w  w w  . j  a va 2 s  .c  om
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);

        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (Exception e) {
        System.out.println("tanslation " + e.getMessage());
        e.printStackTrace();
    }

    return obj;
}