List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:Main.java
private static void writeToFile(String filename, Object object) throws Exception { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(filename))); oos.writeObject(object);/*from w w w . j av a 2s .co m*/ oos.flush(); oos.close(); }
From source file:Main.java
public static final byte[] serialize(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/*from w w w . ja v a 2 s . co m*/ oos.flush(); oos.close(); return baos.toByteArray(); }
From source file:Main.java
public static byte[] objectToStream(Object obj) { try {/* w w w .j a v a 2s . c o m*/ ByteArrayOutputStream buff = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(buff); stream.writeObject(obj); stream.close(); return buff.toByteArray(); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static void SerializeObject(Object object, String path) throws IOException { ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File(path))); oo.writeObject(object);/*from w w w . jav a 2s. c om*/ oo.close(); }
From source file:SerializationUtils.java
public static byte[] serialize(Object obj) { try {/*from www . j a v a 2 s . c om*/ ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(buffer); oos.writeObject(obj); oos.close(); return buffer.toByteArray(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("error writing to byte-array!"); } }
From source file:MainClass.java
public static void desEncrypt(String f1, String f2) throws Exception { SecretKey key = null;/*from ww w. j a va 2s. 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:Main.java
public static void writeObject(OutputStream o, Object obj) throws IOException { ObjectOutputStream oo = new ObjectOutputStream(o); try {/*from w w w .j a v a 2 s .c om*/ oo.writeObject(obj); } finally { oo.close(); } }
From source file:Main.java
public static boolean writeFileByObject(String fileName, Object object) { try {//w w w .j ava 2 s .c o m FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); oos.flush(); oos.close(); fos.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
public static void writeObject(String root, String filename, Object object) { File file = new File(root, filename); try {/*from w ww . j ava2 s .c o m*/ FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); oos.flush(); oos.close(); } catch (Exception e) { Log.e(TAG, String.format("Failed to write [%s]", file), e); } }
From source file:Main.java
public static void saveSeriObj(Context context, String fileName, Object o) throws Exception { String path = context.getFilesDir() + "/"; File dir = new File(path); dir.mkdirs();//from w ww . j av a2s .c o m File f = new File(dir, fileName); if (f.exists()) { f.delete(); } FileOutputStream os = new FileOutputStream(f); ObjectOutputStream objectOutputStream = new ObjectOutputStream(os); objectOutputStream.writeObject(o); objectOutputStream.close(); os.close(); }