List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:com.mayalogy.mayu.io.LocalDataManager.java
public static void serializeAndWriteToFile(String outFile, Object o) throws IOException { FileOutputStream fout = new FileOutputStream(outFile + ".ser"); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(o); oos.close();/* ww w. jav a 2 s . c o m*/ }
From source file:Main.java
/** * This method serializes an object to an output stream. * * @param file The output file//from w w w .j a v a2 s .c o m * @param object The object to be serialized * @exception IOException IOError */ public static void serializeObject(File file, Object object) throws IOException { FileOutputStream fos = new FileOutputStream(file); try { ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(fos)); oos.writeObject(object); oos.flush(); } finally { fos.close(); } }
From source file:Main.java
public static byte[] getBytes(Serializable obj) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(obj); out.flush();/*from w w w.j a v a2 s . c o m*/ byte[] bytes = bout.toByteArray(); bout.close(); out.close(); return bytes; }
From source file:com.googlecode.osde.internal.utils.MapUtil.java
public static String toString(Map<String, String> data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(data == null ? new HashMap<String, String>() : data); out.flush();//from w ww . j a va2s .co m byte[] bytes = baos.toByteArray(); byte[] encoded = Base64.encodeBase64(bytes); return new String(encoded, "UTF-8"); }
From source file:com.evolveum.midpoint.util.SerializationUtil.java
public static String toString(Object object) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); objectOutputStream.close();/*from w w w .j a v a 2s. c o m*/ return new String(Base64.encodeBase64(byteArrayOutputStream.toByteArray())); }
From source file:Main.java
public static void saveSerializableObjectToFile(Object object, FileOutputStream fileOut) { ObjectOutputStream out = null; try {// ww w .j av a2 s. c o m out = new ObjectOutputStream(fileOut); out.writeObject(object); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Test.java
private static void clientStart() { try {/*from w w w .j a va 2 s . c o m*/ InetSocketAddress hostAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2583); AsynchronousSocketChannel clientSocketChannel = AsynchronousSocketChannel.open(); Future<Void> connectFuture = clientSocketChannel.connect(hostAddress); connectFuture.get(); // Wait until connection is done. OutputStream os = Channels.newOutputStream(clientSocketChannel); ObjectOutputStream oos = new ObjectOutputStream(os); for (int i = 0; i < 5; i++) { oos.writeObject("Look at me " + i); Thread.sleep(1000); } oos.writeObject("EOF"); oos.close(); clientSocketChannel.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static byte[] serialize(Object o) throws ObjectStreamException { ByteArrayOutputStream array = new ByteArrayOutputStream(); ObjectOutputStream out = null; try {/*from w w w.j a v a 2 s. co m*/ out = new ObjectOutputStream(array); out.writeObject(o); out.close(); } catch (ObjectStreamException e) { throw e; } catch (IOException e) { // no handle } return array.toByteArray(); }
From source file:Main.java
public static boolean saveObjectToFile(String filePath, Object object) { if (!TextUtils.isEmpty(filePath)) { File cacheFile = null;/*from ww w . j a v a 2s . c om*/ try { cacheFile = new File(filePath); if (cacheFile.exists()) { cacheFile.delete(); } if (!cacheFile.getParentFile().exists()) { cacheFile.getParentFile().mkdirs(); } cacheFile.createNewFile(); } catch (Throwable var6) { var6.printStackTrace(); cacheFile = null; } if (cacheFile != null) { try { FileOutputStream t = new FileOutputStream(cacheFile); GZIPOutputStream gzos = new GZIPOutputStream(t); ObjectOutputStream oos = new ObjectOutputStream(gzos); oos.writeObject(object); oos.flush(); oos.close(); return true; } catch (Throwable var7) { var7.printStackTrace(); } } } return false; }
From source file:gui.CompressDecompress.java
private static byte[] serialize(List<List<BigInteger>> encBuffer) throws IOException { ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o = new ObjectOutputStream(b); o.writeObject(encBuffer); return b.toByteArray(); }