List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.mrgeo.utils.Base64Utils.java
public static String encodeDoubleArray(double[] noData) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; byte[] rawBytes; try {/* ww w . j av a2 s . co m*/ oos = new ObjectOutputStream(baos); oos.writeInt(noData.length); for (int i = 0; i < noData.length; i++) { oos.writeDouble(noData[i]); } oos.flush(); rawBytes = baos.toByteArray(); } finally { if (oos != null) { oos.close(); } baos.close(); } return new String(Base64.encodeBase64(rawBytes)); }
From source file:org.ngrinder.common.util.FileUtil.java
/** * Write object into file.//from www . j a va 2 s . com * * @param file * file * @param obj * obj to be written. */ public static void writeObjectToFile(File file, Object obj) { FileOutputStream fout = null; ObjectOutputStream oout = null; ByteArrayOutputStream bout = null; FileLock lock = null; try { bout = new ByteArrayOutputStream(); oout = new ObjectOutputStream(bout); oout.writeObject(obj); oout.flush(); byte[] byteArray = bout.toByteArray(); fout = new FileOutputStream(file, false); lock = fout.getChannel().lock(); fout.write(byteArray); } catch (Exception e) { LOGGER.error("IO error for file {} : {}", file, e.getMessage()); LOGGER.debug("Details : ", e); } finally { if (lock != null) { try { lock.release(); } catch (Exception e) { LOGGER.error("unlocking is failed for file {}", file, e); } } IOUtils.closeQuietly(bout); IOUtils.closeQuietly(fout); IOUtils.closeQuietly(oout); } }
From source file:fr.eo.util.dumper.Dumper.java
private static void writeDescriptorFile(DumpFilesDescriptor descriptor) { String path = assetFolder + "/" + Const.DUMP_FILE_DESCRIPTOR_NAME; ObjectOutputStream oos = null; try {//from w w w . j a v a2 s . c om oos = new ObjectOutputStream(new FileOutputStream(new File(path))); oos.writeObject(descriptor); oos.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.facebook.infrastructure.utils.FBUtilities.java
public static byte[] serializeToStream(Object o) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] bytes = ArrayUtils.EMPTY_BYTE_ARRAY; try {/*from w ww.j av a 2s. c o m*/ ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(o); oos.flush(); bytes = bos.toByteArray(); oos.close(); bos.close(); } catch (IOException e) { LogUtil.getLogger(FBUtilities.class.getName()).info(LogUtil.throwableToString(e)); } return bytes; }
From source file:org.opoo.press.util.StaleUtils.java
public static void saveLastBuildInfo(Site site) { File file = getLastBuildInfoFile(site); File[] configFiles = site.getConfig().getConfigFiles(); BuildInfo info = new BuildInfo(); info.time = System.currentTimeMillis(); info.siteConfigFilesLength = configFiles.length; ObjectOutputStream oos = null; try {/*from w w w .j av a 2 s. co m*/ oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(info); oos.flush(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(oos); } }
From source file:com.alta189.deskbin.util.CryptUtils.java
private static boolean writeKey(SecretKey key) { FileOutputStream fos = null;/*from w ww .jav a2s . c om*/ ObjectOutputStream out = null; try { if (keyFile.getParentFile() != null) { keyFile.getParentFile().mkdirs(); } fos = new FileOutputStream(keyFile); out = new ObjectOutputStream(fos); out.writeObject(key); out.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(fos); IOUtils.closeQuietly(out); } return false; }
From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java
public static Object deepCopy(Object oldObj) throws IOException, ClassNotFoundException { ObjectOutputStream oos = null; ObjectInputStream ois = null; try {/*from www. j a v a 2 s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(oldObj); oos.flush(); ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); return ois.readObject(); } finally { if (oos != null) oos.close(); if (ois != null) ois.close(); } }
From source file:org.digidoc4j.utils.Helper.java
/** * Serialize object.//from w ww . j ava 2s . co m * * @param object object to be serialized * @param filename name of file to store serialized object in */ public static <T> void serialize(T object, String filename) { FileOutputStream fileOut = null; ObjectOutputStream out = null; try { fileOut = new FileOutputStream(filename); out = new ObjectOutputStream(fileOut); out.writeObject(object); out.flush(); } catch (Exception e) { throw new DigiDoc4JException(e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(fileOut); } }
From source file:org.icelib.beans.ObjectMapping.java
private static Object copy(Object orig) { Object obj = null;//from www . ja v a2 s. c o m try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(orig); out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); obj = in.readObject(); } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return obj; }
From source file:org.jgentleframework.utils.ObjectUtils.java
/** * Returns a deep copy of the given object. * /*from www . ja v a 2 s .com*/ * @param object * the given object need to copied. */ public static Object deepCopy(Object object) { Assertor.notNull(object); Object result = null; try { ByteArrayOutputStream bufOut = new ByteArrayOutputStream(); ObjectOutputStream objOut = new ObjectOutputStream(bufOut); objOut.writeObject(object); objOut.flush(); ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(bufOut.toByteArray())); result = objIn.readObject(); objIn.close(); objOut.close(); bufOut.close(); } catch (IOException e) { if (log.isFatalEnabled()) { log.fatal("Could not copy object [" + object + "]!!", e); } } catch (ClassNotFoundException e) { if (log.isFatalEnabled()) { log.fatal("Could not copy object [" + object + "]!!", e); } } return result; }