List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:download.XBRLZipDownloader.java
/** * Saves the RSSFilingData in the same folder of the downloaded xbrl data * @param outputPath/*from w w w. ja v a2s .c o m*/ * @param rssData */ private void saveRSSFilingData(String outputPath, RSSFilingData rssData) { try { FileOutputStream os = new FileOutputStream(new File(outputPath)); ObjectOutputStream objStream = new ObjectOutputStream(os); objStream.writeObject(rssData); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:net.fizzl.redditengine.impl.PersistentCookieStore.java
/** * Save cookies to a file/*from www . j a v a 2 s . c om*/ */ private void save() { RedditApi api = DefaultRedditApi.getInstance(); Context ctx = api.getContext(); try { FileOutputStream fos = ctx.openFileOutput(cookiestore, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); SerializableCookieStore tempStore = new SerializableCookieStore(); for (Cookie c : getCookies()) { tempStore.addCookie(c); } oos.writeObject(tempStore); oos.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.g3net.tool.ObjectUtils.java
/** * /*from w ww . j a va2s . c om*/ * @param o ???java??,??? * @return * @throws Exception */ public static byte[] serializeObject(Object o) throws Exception { ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; if (o == null) { return null; } try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(o); oos.flush(); return bos.toByteArray(); } finally { if (oos != null) { oos.close(); } } }
From source file:com.griddynamics.jagger.util.SerializationUtils.java
public static String toString(Serializable o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try {//from w w w .ja v a 2s . com if (useJBoss) { oos = new JBossObjectOutputStream(baos); } else { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); } oos.writeObject(o); } catch (IOException e) { log.error("Serialization exception ", e); throw new TechnicalException(e); } finally { String s = new String(Base64Coder.encode(baos.toByteArray())); if (s.isEmpty()) { log.info("toString({}, '{}', '{}')", toStringCount.getAndIncrement(), s, o); } try { Closeables.close(oos, true); } catch (IOException e) { log.warn("IOException should not have been thrown.", e); } return s; } }
From source file:org.blanco.techmun.android.cproviders.MesasFetcher.java
private void saveOnCache(Context context, Mesas mesas) { try {/*from w ww . j a v a2 s . c o m*/ FileOutputStream mesasFOS = context.openFileOutput("mesas.df", Context.MODE_PRIVATE); ObjectOutputStream mesasOOS = new ObjectOutputStream(mesasFOS); mesasOOS.writeObject(mesas); mesasOOS.close(); PreferenceManager.getDefaultSharedPreferences(context).edit() .putLong("mesas_last_cache_saved", System.currentTimeMillis()).commit(); } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be saved", e); } }
From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java
private static byte[] stringMapToBytes(Object object) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(object);/*from w w w . j a v a 2 s . c o m*/ out.flush(); return baos.toByteArray(); }
From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.UkbDocumentDependentDictionaryInventory.java
public UkbDocumentDependentDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath) throws FileNotFoundException, IOException { // Open the serialized version or create it from scratch try {//w w w .ja v a2 s .com // System.out.println("Trying to load dictionary from serializable."); ObjectInputStream dictionaryReader = new ObjectInputStream( new BZip2CompressorInputStream(new FileInputStream(serializiblePath))); dictionary = (UkbDictionary) dictionaryReader.readObject(); dictionaryReader.close(); // System.out.println("Loaded dictionary from serializable."); } catch (Exception e) { // System.out.println("Trying to load dictionary from input."); dictionary = new UkbDictionary(inputPath, neededMentionsPath); System.out.println("Loaded dictionary from input."); ObjectOutputStream dictionaryWriter = new ObjectOutputStream( new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath))); dictionaryWriter.writeObject(dictionary); dictionaryWriter.close(); // System.out.println("Stored dictionary in serializable."); } }
From source file:com.jiramot.foursquare.android.FSAPITest.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w ww.j a v a 2 s . com venue = (Button) findViewById(R.id.button); OnClickListener venues = new OnClickListener() { @Override public void onClick(View v) { String aa = null; try { aa = searchVenue(); JSONObject obj = new JSONObject(aa); // Log.i("fsapitest", obj.toString(2)); JSONObject response = obj.getJSONObject("response"); JSONArray groups = response.getJSONArray("groups"); JSONObject element = groups.getJSONObject(0); JSONArray items = element.getJSONArray("items"); File sdcardpath = Environment.getExternalStorageDirectory(); File f = new File(sdcardpath, "test" + count + ".txt"); FileOutputStream outStream = new FileOutputStream(f); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(outStream)); for (int i = 0; i < items.length(); i++) { JSONObject item = items.getJSONObject(i); Log.i("corso", "item " + i + " -- " + item.getString("id")); Log.i("corso", "item " + i + " -- " + item.getString("name")); } // out.writeObject(items.toString(2)); out.flush(); out.close(); outStream.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; OnClickListener friends = new OnClickListener() { @Override public void onClick(View v) { venue.setText("friends"); try { String result = foursquare.request("users/self/friends"); JSONObject obj = new JSONObject(result); JSONObject response = obj.getJSONObject("response"); JSONObject friends = response.getJSONObject("friends"); JSONArray items = friends.getJSONArray("items"); for (int i = 0; i < items.length(); i++) { JSONObject item = items.getJSONObject(i); Log.i("debug", item.getString("id") + " - " + item.getString("firstName") + " " + item.getString("lastName")); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; venue.setOnClickListener(friends); init(getIntent()); // JSONObject response = obj.getJSONObject("response"); // JSONArray venues = response.getJSONArray("groups"); // File sdcardpath = Environment.getExternalStorageDirectory(); // File f = new File(sdcardpath,"test"+count+".txt"); // FileOutputStream outStream = new FileOutputStream(f); // ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(outStream)); // out.writeObject(obj.toString(2)); // for (int i=0; i<venues.length(); i++) { // JSONObject venue = venues.getJSONObject(i); // out.writeObject(venue.toString(2)); // Log.i("corso", venue.getString("id")); // Log.i("corso", venue.getString("name")); // } // out.flush(); // out.close(); // outStream.close(); // // count++; // Log.i("fsapitest", "calls: "+count); // }
From source file:sawtooth.examples.jvmsc.JvmScHandler.java
/** * the method that returnsa byte[] from an object. *//*from w w w . ja v a 2 s . c o m*/ public static byte[] dataToByteArray(Object data) throws IOException, ClassNotFoundException { ByteArrayOutputStream input = new ByteArrayOutputStream(); ObjectOutputStream output = new ObjectOutputStream(input); output.writeObject(data); return input.toByteArray(); }