List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:Main.java
public static Object readFileByObject(String fileName) { try {//w w w .j a v a 2 s. c o m FileInputStream fis = new FileInputStream(fileName); ObjectInputStream ois = new ObjectInputStream(fis); Object o = ois.readObject(); ois.close(); fis.close(); return o; } catch (Exception e) { return null; } }
From source file:Main.java
public static Object deserializeObject(byte[] b) { try {//from ww w. j a v a2s . 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
/** * Receives an object through bluetooth. *///from www .java 2 s. co m public static Object bluetoothReadObject(BluetoothSocket socket) { ObjectInputStream oIS; try { oIS = new ObjectInputStream(socket.getInputStream()); Object object = oIS.readObject(); return object; } catch (Exception e) { return null; } }
From source file:Main.java
public static Object readAsObject(File source) throws IOException, ClassNotFoundException { FileInputStream in = new FileInputStream(source); try {/*from w w w . java 2s. c om*/ ObjectInputStream oi = new ObjectInputStream(in); return oi.readObject(); } finally { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static Object readSerializableObjectFromFile(FileInputStream fileIn) { Object b = null;/* w w w. j a v a2 s . co m*/ 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:Main.java
/** Read the object from Base64 string. */ public static Object fromString(String s) throws IOException, ClassNotFoundException { byte[] data = Base64.decode(s, 0); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); Object o = ois.readObject();//from w w w.ja va 2 s . co m ois.close(); return o; }
From source file:Main.java
public static Object byteToObject(byte[] data) throws IOException, ClassNotFoundException { ByteArrayInputStream inputStream = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(inputStream); return is.readObject(); }
From source file:Main.java
public static Object convertFromBytes(byte[] bytes) throws IOException, ClassNotFoundException { try {/*from www. j a v a 2 s. c om*/ ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInput in = new ObjectInputStream(bis); return in.readObject(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Object readObjectFromFile(String fileName) { ObjectInputStream ois = null; FileInputStream fis = null;//from w w w . j a v a2s .c o m try { fis = new FileInputStream(fileName); ois = new ObjectInputStream(fis); return ois.readObject(); } catch (Exception e) { } finally { if (ois != null) try { ois.close(); ois = null; } catch (IOException e) { } if (fis != null) try { fis.close(); fis = null; } catch (IOException e) { } } return null; }
From source file:Main.java
public static Object getObject(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream bi = new ByteArrayInputStream(bytes); ObjectInputStream oi = new ObjectInputStream(bi); Object obj = oi.readObject(); bi.close();/* www .ja v a 2 s . com*/ oi.close(); return obj; }