List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:com.antbrains.crf.hadoop.InstanceGenerator.java
public static String object2String(Object o) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(o);/*from w w w.ja va 2 s . c om*/ so.flush(); byte[] arr = Base64.encodeBase64(bo.toByteArray()); return new String(arr, "UTF8"); }
From source file:org.forgerock.openidm.quartz.impl.RepoJobStoreUtils.java
/** * Converts a serializable object into a String. * // w ww . j a va 2 s. co m * @param object the object to serialize. * @return a string representation of the serialized object. * @throws Exception */ public static String serialize(Serializable object) throws JobPersistenceException { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); oos.close(); //return new String(Base64Coder.encode(baos.toByteArray())); return new String(Base64.encodeBase64(baos.toByteArray())); } catch (Exception e) { e.printStackTrace(); throw new JobPersistenceException(e.getMessage()); } }
From source file:Main.java
/** * Serialize an object.//from w ww . j a v a 2 s . c o m * @param obj a serializable object. * @return a byte array of the serialized object or null if an error occurs. */ public static byte[] serialize(Object obj) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.flush(); baos.flush(); return baos.toByteArray(); } catch (IOException e) { return null; } finally { try { if (oos != null) oos.close(); } catch (IOException e) { } } }
From source file:org.rhq.coregui.server.gwt.ObjectFilter.java
private static int sizeOf(Object object) { try {//from w ww.ja v a 2s. co m ByteArrayOutputStream baos = new ByteArrayOutputStream(50000); ObjectOutputStream o = new ObjectOutputStream(baos); o.writeObject(object); o.flush(); return baos.size(); } catch (Exception e) { } return -1; }
From source file:net.dontdrinkandroot.utils.lang.SerializationUtils.java
@SuppressWarnings("unchecked") public static <T extends Serializable> T fastClone(T object) { Object obj = null;// w w w . java 2s . c om try { /* Write the object out to a byte array */ FastByteArrayOutputStream fbos = new FastByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(fbos); out.writeObject(object); out.flush(); out.close(); /* Retrieve an input stream from the byte array and read a copy of the object back in. */ ObjectInputStream in = new ObjectInputStream(fbos.getInputStream()); obj = in.readObject(); } catch (IOException e) { throw new SerializationException(e); } catch (ClassNotFoundException cnfe) { throw new SerializationException(cnfe); } return (T) obj; }
From source file:Main.java
public static boolean saveObjectToFile(String filePath, Object object) { if (!TextUtils.isEmpty(filePath)) { File cacheFile = null;/*from w ww .ja v a2 s . c o m*/ 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:org.commonjava.indy.folo.FoloUtils.java
public static InputStream toInputStream(TrackedContent f) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(f);//from w w w. j av a 2 s . c om oos.flush(); oos.close(); return new ByteArrayInputStream(baos.toByteArray()); }
From source file:de.kbs.acavis.service.SerializationHelper.java
public static String serializePublicationIdentifier(PublicationIdentifier identifier) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(identifier);//w w w .j av a 2 s .c om so.flush(); String serialization = bo.toString(); so.close(); bo.close(); return serialization; }
From source file:de.kbs.acavis.service.SerializationHelper.java
public static String serializeAuthorIdentifier(AuthorIdentifier identifier) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(identifier);// w ww. j ava2s. co m so.flush(); String serialization = bo.toString(); so.close(); bo.close(); return serialization; }
From source file:prototype.samples.AsyncSigning.java
private static <T> void serialize(T container, String path) throws IOException { FileOutputStream fileOut = new FileOutputStream(path); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(container);//from w w w .j a v a 2 s. c o m out.flush(); out.close(); fileOut.close(); }