List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:Main.java
static public Object setObjectBytes(byte[] b) throws IOException, ClassNotFoundException { ByteArrayInputStream baos = new ByteArrayInputStream(b); ObjectInputStream oos = new ObjectInputStream(baos); oos.close();//ww w . j a v a2s . c o m return oos.readObject(); }
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();/*w w w .j a v a 2 s . co m*/ oi.close(); return obj; }
From source file:Main.java
public static Object readObject(InputStream o) throws IOException, ClassNotFoundException { ObjectInputStream oo = new ObjectInputStream(o); try {/* ww w .j a va 2 s .c om*/ return oo.readObject(); } finally { oo.close(); } }
From source file:Main.java
public static Object ByteToObject(byte[] bytes) { Object obj = null;// www.j ava 2 s . c om try { // bytearray to object ByteArrayInputStream bi = new ByteArrayInputStream(bytes); ObjectInputStream oi = new ObjectInputStream(bi); obj = oi.readObject(); bi.close(); oi.close(); } catch (Exception e) { e.printStackTrace(); } return obj; }
From source file:Main.java
/** * Returns a object from the given byte array. * /*from ww w . j a va2 s. c om*/ * @param bytes * array to convert * @return object */ public static Object bytesToObject(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream is = new ObjectInputStream(bais); return is.readObject(); }
From source file:Main.java
public static Object readFileByObject(String fileName) { try {//from w w w. ja v a 2 s . c om 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 deserializable(byte[] bytes) { Object obj = null;//from w ww . j a v a 2s . co m 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; }
From source file:Main.java
public static Object getSerializable(byte[] bytes) { Object obj = null;//w w w .ja va 2s .co m try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); obj = ois.readObject(); ois.close(); bis.close(); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } return obj; }
From source file:Main.java
public static List copyBySerialize(List src) throws IOException, ClassNotFoundException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src);//from ww w .j av a2s .c om ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); List dest = (List) in.readObject(); return dest; }
From source file:Main.java
public static Object readGZipCompressedObject(InputStream in) throws IOException, ClassNotFoundException { GZIPInputStream gis = new GZIPInputStream(in); ObjectInputStream ois = new ObjectInputStream(gis); return ois.readObject(); }