List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:Main.java
/** * Convert Object to Byte Array//from w ww. ja v a 2 s .c om * * @param obj * @return * @throws IOException */ public static byte[] convertObjectToByteArray(Object obj) throws IOException { ObjectOutputStream os = null; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000); os = new ObjectOutputStream(new BufferedOutputStream(byteStream)); os.flush(); os.writeObject(obj); os.flush(); byte[] sendBuf = byteStream.toByteArray(); os.close(); return sendBuf; }
From source file:com.taobao.tair.etc.TranscoderUtil.java
public static byte[] serialize(Object o) { if (o == null) { throw new NullPointerException("Can't serialize null"); }/*from w w w . ja v a 2s . c om*/ byte[] rv = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(o); os.close(); bos.close(); rv = bos.toByteArray(); } catch (IOException e) { throw new IllegalArgumentException("Non-serializable object", e); } return rv; }
From source file:com.projity.exchange.LocalFileImporter.java
public static Job getExportFileJob(final FileImporter importer) { final Job job = new Job(importer.getJobQueue(), "exportFile", //$NON-NLS-1$ Messages.getString("LocalFileImporter.Exporting"), true); //$NON-NLS-1$ job.addRunnable(new JobRunnable("Export", 1.0f) { //$NON-NLS-1$ public Object run() throws Exception { DataUtil serializer = new DataUtil(); System.out.println("Serialization..."); //$NON-NLS-1$ long t1 = System.currentTimeMillis(); DocumentData projectData = serializer.serializeDocument(importer.getProject()); projectData.setMaster(true); projectData.setLocal(true);//from w ww . ja v a 2 s.co m long t2 = System.currentTimeMillis(); System.out.println("Serialization...Done in " + (t2 - t1) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ File f = new File(importer.getFileName()); System.out.println("Saving " + f + "..."); //$NON-NLS-1$ //$NON-NLS-2$ t1 = System.currentTimeMillis(); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f)); out.writeObject(VERSION); out.writeObject(projectData); out.close(); t2 = System.currentTimeMillis(); System.out.println("Saving...Done in " + (t2 - t1) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$ setProgress(1.0f); return null; } }); return job; }
From source file:org.terracotta.management.model.cluster.ClusterTest.java
@SuppressWarnings("unchecked") private static <T> T copy(T o) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/*ww w . j a v a 2s .com*/ oos.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); return (T) in.readObject(); }
From source file:org.alfresco.rad.test.AlfrescoTestRunner.java
public static String serializableToString(Serializable serializable) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(serializable);/*from ww w. j a v a 2s . c o m*/ oos.close(); String string = Base64.encodeBase64URLSafeString(baos.toByteArray()); return string; }
From source file:hydrograph.engine.hadoop.inputformat.TupleMemoryInputFormat.java
public static void storeTupleGenerator(Configuration conf, String key, ITupleGenerator tupleGenerator, long numTuples) { LOG.debug("Storing ITupleGenerator: {}", tupleGenerator); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutputStream out; try {/*from w ww . j av a 2 s.com*/ out = new ObjectOutputStream(stream); out.writeObject(tupleGenerator); out.close(); } catch (IOException e) { throw new RuntimeException(e); } String confVal = numTuples + ":" + encodeBytes(stream.toByteArray()); conf.set(key, confVal); }
From source file:com.yahoo.spaclu.data.extract.ExtractFeatureSpark.java
/** * @deprecated//from w w w. j a va 2s .c o m */ public static boolean writeToHDFS(Object object, String fileName) { // Create a default hadoop configuration Configuration conf = new Configuration(); // Specifies a new file in HDFS. Path filenamePath = new Path(fileName); try { // Parse created config to the HDFS FileSystem fs = FileSystem.get(conf); // if the file already exists delete it. if (fs.exists(filenamePath)) { throw new IOException(); } FSDataOutputStream fos = fs.create(filenamePath); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object); fos.close(); oos.close(); return true; } catch (IOException ioe) { ioe.printStackTrace(); return false; } }
From source file:info.usbo.skypetwitter.Run.java
public static void save_file() { try {//from www. j a v a2s . co m FileOutputStream fos = new FileOutputStream(work_dir + "\\twitter_ids.data"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(twitter_ids); oos.close(); fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } try { FileOutputStream fos = new FileOutputStream(work_dir + "\\vk_ids.data"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(vk_ids); oos.close(); fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:be.vdab.util.Programma.java
private static void schrijweg(TreeSet<Voertuig> verzameling, String file) throws FileNotFoundException, IOException { FileOutputStream outputStream = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(outputStream); oos.writeObject(verzameling);//TreeSet implements Serializable, superklasse AbstractSet implements NIET Serializable, maar heeft een no-args constructor-->dus serialiseerbaar oos.close(); //voertuig serialiseerbaar maken want die zit in de treeSet, maar de comparator als innerclasses moeten ook serialiseerbaar gemaaakt worden! }
From source file:it.unimi.di.big.mg4j.io.IOFactories.java
public static void storeObject(final IOFactory ioFactory, final Object object, final String filename) throws IOException { final ObjectOutputStream oos = new ObjectOutputStream( new FastBufferedOutputStream(ioFactory.getOutputStream(filename))); oos.writeObject(object);//from w ww.ja v a 2 s.c o m oos.close(); }