List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:org.terracotta.management.cli.rest.HttpServices.java
private static void save(String filename, Object o) throws IOException { File path = new File(System.getProperty("user.home"), ".tc/mgmt"); File file = new File(path, filename); ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file)); try {/*from w w w . j a v a2s .c o m*/ objectOutputStream.writeObject(o); } finally { objectOutputStream.close(); } }
From source file:conceptnet.ConceptBuilder.java
public static void saveConcept(Concept c) { String path = conceptPath + c.name; File f = new File(path); if (f.exists() || f.isDirectory()) { System.out.println("Try to save a concept that is already saved: " + c.name); return;/*from w ww . j a va2 s.c o m*/ } try { ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream(path)); ois.writeObject(c); ois.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java
public static byte[] toBytes(String[] strings) { try {//from w ww . j a v a 2 s .com ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(strings); objectOutputStream.flush(); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { NeoLogger.error("Unable to convert ''{0}'' to byte[]", Arrays.toString(strings)); } return null; }
From source file:Main.java
public static void writeObjectToFile(Object object, File file) { ObjectOutputStream oos = null; try {//from www.j a va2s. co m FileOutputStream fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeObject(object); } catch (IOException e) { e.printStackTrace(); } finally { try { if (oos != null) { oos.close(); } } catch (IOException e) { e.printStackTrace(); } } }
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);/* w ww . j av a 2 s.co m*/ 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:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java
private static String getKeyOfNonSerializableStringMapEntry(Map<String, ?> data) { for (Map.Entry<String, ?> entry : data.entrySet()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from ww w.java2 s .com ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(entry.getValue()); out.flush(); } catch (IOException e) { return entry.getKey(); } } return null; }
From source file:cam.cl.kilo.RESTBarcode.java
/** * Serialise an object as a Base 64 string. * * @param o The object to serialise//from w w w .j a v a2 s. co m * @return Base64-encoded string. * @throws IOException */ private static String toString(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.close(); return Base64.encodeBase64String(baos.toByteArray()); }
From source file:edu.tufts.vue.util.Encryption.java
private static synchronized Key getKey() { try {/* w w w .j a v a 2 s . c o m*/ if (key == null) { File keyFile = new File( VueUtil.getDefaultUserFolder().getAbsolutePath() + File.separator + KEY_FILE); if (keyFile.exists()) { ObjectInputStream is = new ObjectInputStream(new FileInputStream(keyFile)); key = (Key) is.readObject(); is.close(); } else { key = KeyGenerator.getInstance(algorithm).generateKey(); ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(keyFile)); os.writeObject(key); os.close(); } return key; } else { return key; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:it.restrung.rest.utils.IOUtils.java
/** * Serializes ans saves a Serializable object to a file * * @param object the source object/*from w ww . ja va 2 s . co m*/ * @param file the target file */ static public void saveSerializableObjectToDisk(Object object, File file) { try { file.delete(); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); GZIPOutputStream gzos = new GZIPOutputStream(fos); ObjectOutputStream out = new ObjectOutputStream(gzos); out.writeObject(object); out.flush(); out.close(); } catch (FileNotFoundException e) { Log.d(IOUtils.class.getName(), "Error, file not found for save serializable object to disk"); throw new RuntimeException(e); } catch (IOException e) { Log.d(IOUtils.class.getName(), "Error on save serializable object"); throw new RuntimeException(e); } }
From source file:de.tudarmstadt.ukp.dkpro.core.frequency.tfidf.util.TfidfUtils.java
public static void serialize(Object object, String fileName) throws Exception { File file = new File(fileName); if (!file.exists()) FileUtils.touch(file);//from w w w. ja v a 2s . c o m if (file.isDirectory()) { throw new IOException("A directory with that name exists!"); } ObjectOutputStream objOut; objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); objOut.writeObject(object); objOut.flush(); objOut.close(); }