List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:SerializationUtils.java
public static Object deserialize(byte[] bytes) throws ClassNotFoundException { try {/* www.jav a2s. c om*/ ByteArrayInputStream input = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(input); return ois.readObject(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("error reading from byte-array!"); } }
From source file:Util.java
public static Object decompress(byte[] data) { if (data == null) { return null; }/*from w w w.ja va 2 s.co m*/ try { ByteArrayInputStream bais = new ByteArrayInputStream(data); GZIPInputStream gin = new GZIPInputStream(bais); ObjectInputStream ois = new ObjectInputStream(gin); return ois.readObject(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Object readSeriObject(Context context, String fileName) throws Exception { String path = context.getFilesDir() + "/"; File dir = new File(path); dir.mkdirs();// w w w. ja v a 2 s . c om File file = new File(dir, fileName); InputStream is = new FileInputStream(file); ObjectInputStream objectInputStream = new ObjectInputStream(is); Object o = objectInputStream.readObject(); return o; }
From source file:MainClass.java
public static void desEncrypt(String f1, String f2) throws Exception { SecretKey key = null;/*from ww w . j a v a2 s .c om*/ ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("DESKey.ser")); key = (SecretKey) keyFile.readObject(); keyFile.close(); KeyGenerator keygen = KeyGenerator.getInstance("DES"); key = keygen.generateKey(); ObjectOutputStream keyFileout = new ObjectOutputStream(new FileOutputStream("DESKey.ser")); keyFileout.writeObject(key); keyFileout.close(); Cipher cipher = null; cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); BufferedInputStream in = new BufferedInputStream(new FileInputStream(f1)); CipherOutputStream out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(f2)), cipher); int i; do { i = in.read(); if (i != -1) out.write(i); } while (i != -1); in.close(); out.close(); }
From source file:io.cloudslang.content.httpclient.build.CookieStoreBuilder.java
public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream b = new ByteArrayInputStream(bytes); ObjectInputStream o = new ObjectInputStream(b); return o.readObject(); }
From source file:Main.java
public static Object toObject(byte[] bytes) { Object obj = null;//from w w w. j a va 2s .c o m try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); obj = ois.readObject(); ois.close(); bis.close(); } catch (Exception ex) { ex.printStackTrace(); } return obj; }
From source file:Main.java
public static Object getObjectFromFile(String filePath) { FileInputStream freader;//from ww w. j a va 2 s .com Object ret = null; try { freader = new FileInputStream(filePath); ObjectInputStream objectInputStream = new ObjectInputStream(freader); ret = objectInputStream.readObject(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; }
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 ava 2s .com return object; }
From source file:de.zib.gndms.gritserv.tests.EncTest.java
public static void dryRun(EndpointReferenceType epr) throws Exception { ByteArrayOutputStream bse = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bse); String sepr = ObjectSerializer.toString(epr, QNAME); System.out.println(sepr);//ww w.java 2 s . c om oos.writeObject(sepr); Base64 b64 = new Base64(0, new byte[] {}, true); String uuepr = b64.encodeToString(bse.toByteArray()); System.out.println("uuepr: \"" + uuepr + "\""); byte[] bt = b64.decode(uuepr.getBytes()); ByteArrayInputStream bis = new ByteArrayInputStream(bt); ObjectInputStream ois = new ObjectInputStream(bis); String eprs = (String) ois.readObject(); System.out.println(eprs); }
From source file:com.pcms.core.util.ObjectUtil.java
public static Object deserialize(byte[] bytes) { ByteArrayInputStream bais = null; try {//ww w .j ava2s .c o m bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); return ois.readObject(); } catch (Exception e) { LOG.error(e.getMessage()); } return null; }