List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java
@Override public void create() { try {//ww w .j a va 2 s . c o m setContentView(R.layout.news_feed_main); setTitle(R.string.news_feed); setTopbarTitleTypeface(Typeface.NORMAL); mainLayout = findViewById(R.id.news_feed_main_layout); listView = (RecyclerView) findViewById(R.id.news_feed_main_list); listView.setLayoutManager(new LinearLayoutManager(this)); progressLayout = findViewById(R.id.news_feed_main_progress_layout); refreshLayout = (SwipeRefreshLayout) findViewById(R.id.news_feed_main_refresh); refreshLayout.setEnabled(false); refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { loadRSS(); } }); currentIntent = getIntent(); Bundle store = currentIntent.getExtras(); widget = (Widget) store.getSerializable("Widget"); if (widget == null) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100); return; } if (!TextUtils.isEmpty(widget.getTitle())) { setTopBarTitle(widget.getTitle()); } setTopBarTitleColor(Color.parseColor("#000000")); setTopBarLeftButtonTextAndColor(getResources().getString(R.string.news_home_button), Color.parseColor("#000000"), true, new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); try { if (widget.getPluginXmlData().length() == 0) { if (currentIntent.getStringExtra("WidgetFile").length() == 0) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } } } catch (Exception e) { handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 3000); return; } cachePath = widget.getCachePath() + "/feed-" + widget.getOrder(); File cache = new File(this.cachePath); if (!cache.exists()) { cache.mkdirs(); } // 3 seconds String widgetMD5 = Utils.md5(widget.getPluginXmlData()); File cacheData = new File(cachePath + "/cache.data"); if (cacheData.exists() && cacheData.length() > 0) { String cacheMD5 = readFileToString(cachePath + "/cache.md5").replace("\n", ""); if (cacheMD5.equals(widgetMD5)) { useCache = true; } else { File[] files = cache.listFiles(); for (File file : files) { file.delete(); } try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(cachePath + "/cache.md5"))); bw.write(widgetMD5); bw.close(); Log.d("IMAGES PLUGIN CACHE MD5", "SUCCESS"); } catch (Exception e) { Log.w("IMAGES PLUGIN CACHE MD5", e); } } } isOnline = NetworkUtils.isOnline(this); if (!isOnline && !useCache) { handler.sendEmptyMessage(NEED_INTERNET_CONNECTION); return; } new Thread() { @Override public void run() { timer = new Timer("EventsTimer", true); EntityParser parser; if (widget.getPluginXmlData().length() > 0) { parser = new EntityParser(widget.getPluginXmlData()); } else { String xmlData = readXmlFromFile(currentIntent.getStringExtra("WidgetFile")); parser = new EntityParser(xmlData); } parser.parse(); Statics.color1 = parser.getColor1(); Statics.color2 = parser.getColor2(); Statics.color3 = parser.getColor3(); Statics.color4 = parser.getColor4(); Statics.color5 = parser.getColor5(); handler.sendEmptyMessage(COLORS_RECEIVED); title = (widget.getTitle().length() > 0) ? widget.getTitle() : parser.getFuncName(); items = parser.getItems(); if ("rss".equals(parser.getFeedType())) { Statics.isRSS = true; AndroidSchedulers.mainThread().createWorker().schedule(new Action0() { @Override public void call() { refreshLayout.setColorSchemeColors(Statics.color3); } }); feedURL = parser.getFeedUrl(); if (isOnline) { FeedParser reader = new FeedParser(parser.getFeedUrl()); items = reader.parseFeed(); encoding = reader.getEncoding(); if (items.size() > 0) { try { ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(cachePath + "/cache.data")); oos.writeObject(items); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); } } Statics.isRSS = true; AndroidSchedulers.mainThread().createWorker().schedule(new Action0() { @Override public void call() { refreshLayout.setEnabled(true); } }); } else { try { ObjectInputStream ois = new ObjectInputStream( new FileInputStream(cachePath + "/cache.data")); items = (ArrayList<FeedItem>) ois.readObject(); ois.close(); } catch (Exception e) { e.printStackTrace(); } } } else { Statics.isRSS = false; AndroidSchedulers.mainThread().createWorker().schedule(new Action0() { @Override public void call() { refreshLayout.setEnabled(false); } }); } for (int i = 0; i < items.size(); i++) { items.get(i).setTextColor(widget.getTextColor()); items.get(i).setDateFormat(widget.getDateFormat()); } funcName = parser.getFuncName(); selectShowType(); } }.start(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSavePatch(SpinCADPatch m) { File fileToBeSaved = new File(prefs.get("MRUPatchFolder", "") + "/" + m.patchFileName); String filePath = fileToBeSaved.getPath(); loadRecentPatchFileList();// w w w . j a va2s .c om FileOutputStream fos; ObjectOutputStream oos = null; try { fos = new FileOutputStream(filePath); oos = new ObjectOutputStream(fos); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { oos.writeObject(m); } catch (IOException e1) { e1.printStackTrace(); } try { oos.flush(); oos.close(); } catch (IOException e) { e.printStackTrace(); } finally { saveMRUPatchFolder(filePath); recentPatchFileList.add(fileToBeSaved); saveRecentPatchFileList(); } }
From source file:pl.otros.logview.api.store.file.FileLogDataStore.java
@Override public void add(LogData... logDatas) { ObjectOutputStream oout = null; ByteArrayOutputStream byteArrayOutputStream = null; Arrays.sort(logDatas, logDataTimeComparator); try {/* w ww.j a v a 2 s.co m*/ HashMap<Integer, Long> newLogDataPosition = new HashMap<>(logDatas.length); long length = randomAccessFile.length(); LOGGER.trace(String.format("Setting position in file %s to %d", randomAccessFile.getFD().toString(), length)); randomAccessFile.seek(length); for (LogData logData1 : logDatas) { byteArrayOutputStream = new ByteArrayOutputStream(); oout = new ObjectOutputStream(byteArrayOutputStream); logData1.setId(getNextLogId()); int logDataId = logData1.getId(); long positionInFile = randomAccessFile.length(); oout.writeObject(logData1); oout.flush(); randomAccessFile.writeInt(byteArrayOutputStream.size()); randomAccessFile.write(byteArrayOutputStream.toByteArray()); newLogDataPosition.put(Integer.valueOf(logDataId), Long.valueOf(positionInFile)); marks.put(Integer.valueOf(logDataId), logData1.isMarked()); marksColor.put(Integer.valueOf(logDataId), logData1.getMarkerColors()); if (logData1.getNote() != null) { notable.addNoteToRow(logDataId, logData1.getNote()); } } storeIdFilePositionMapping.putAll(newLogDataPosition); // TODO sorting by date! for (LogData logData : logDatas) { // logDatasId.add(new IdAndDate(Integer.valueOf(logDatas[i].getId()), logDatas[i].getDate())); if (logDatasId.size() == 0 || logData.getDate().compareTo(logDatasId.get(logDatasId.size() - 1).date) >= 0) { logDatasId.add(new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } else { int index = getIndexToInsert(logData.getDate(), 0, logDatasId.size() - 1, logDatasId.size() / 2); logDatasId.add(index, new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } } ensureLimit(); } catch (IOException e) { LOGGER.error(String.format("Error adding %d events: %s", logDatas.length, e.getMessage())); e.printStackTrace(); } finally { IOUtils.closeQuietly(oout); } }
From source file:org.mortbay.ijetty.IJetty.java
License:asdf
protected void setStoredJettyVersion(int version) { File jettyDir = __JETTY_DIR;//from ww w. ja va 2s.c om if (!jettyDir.exists()) { return; } File versionFile = new File(jettyDir, "version.code"); ObjectOutputStream oos = null; try { FileOutputStream fos = new FileOutputStream(versionFile); oos = new ObjectOutputStream(fos); oos.writeInt(version); oos.flush(); } catch (Exception e) { Log.e(TAG, "Problem writing jetty version", e); } finally { if (oos != null) { try { oos.close(); } catch (Exception e) { Log.d(TAG, "Error closing version.code output stream", e); } } } }
From source file:pl.otros.logview.store.file.FileLogDataStore.java
@Override public void add(LogData... logDatas) { ObjectOutputStream oout = null; ByteArrayOutputStream byteArrayOutputStream = null; Arrays.sort(logDatas, logDataTimeComparator); try {//from ww w . j ava2 s. c o m HashMap<Integer, Long> newLogDataPosition = new HashMap<Integer, Long>(logDatas.length); long length = randomAccessFile.length(); LOGGER.finest(String.format("Setting position in file %s to %d", randomAccessFile.getFD().toString(), length)); randomAccessFile.seek(length); for (int i = 0; i < logDatas.length; i++) { byteArrayOutputStream = new ByteArrayOutputStream(); oout = new ObjectOutputStream(byteArrayOutputStream); logDatas[i].setId(getNextLogId()); int logDataId = logDatas[i].getId(); long positionInFile = randomAccessFile.length(); oout.writeObject(logDatas[i]); oout.flush(); randomAccessFile.writeInt(byteArrayOutputStream.size()); randomAccessFile.write(byteArrayOutputStream.toByteArray()); newLogDataPosition.put(Integer.valueOf(logDataId), Long.valueOf(positionInFile)); marks.put(Integer.valueOf(logDataId), logDatas[i].isMarked()); marksColor.put(Integer.valueOf(logDataId), logDatas[i].getMarkerColors()); if (logDatas[i].getNote() != null) { notable.addNoteToRow(logDataId, logDatas[i].getNote()); } } storeIdFilePositionMapping.putAll(newLogDataPosition); // TODO sorting by date! for (int i = 0; i < logDatas.length; i++) { LogData logData = logDatas[i]; // logDatasId.add(new IdAndDate(Integer.valueOf(logDatas[i].getId()), logDatas[i].getDate())); if (logDatasId.size() == 0 || logData.getDate().compareTo(logDatasId.get(logDatasId.size() - 1).date) >= 0) { logDatasId.add(new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } else { int index = getIndexToInsert(logData.getDate(), 0, logDatasId.size() - 1, logDatasId.size() / 2); logDatasId.add(index, new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } } ensureLimit(); } catch (IOException e) { LOGGER.severe(String.format("Error adding %d events: %s", logDatas.length, e.getMessage())); e.printStackTrace(); } finally { IOUtils.closeQuietly(oout); } }
From source file:ponzu.impl.test.Verify.java
private static String encodeObject(Object actualObject) { try {/*from w ww .ja v a2s. co m*/ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(actualObject); objectOutputStream.flush(); objectOutputStream.close(); String string = new Base64(76, LINE_SEPARATOR, false) .encodeAsString(byteArrayOutputStream.toByteArray()); String trimmedString = removeFinalNewline(string); return addFinalNewline(trimmedString); } catch (IOException e) { throw new AssertionError(e); } }
From source file:net.lightbody.bmp.proxy.jetty.http.HttpServer.java
/** Save the HttpServer * The server is saved by serialization to the given filename or URL. * * @param saveat A file or URL to save the configuration at. * @exception MalformedURLException // w w w . j av a2 s .co m * @exception IOException */ public void save(String saveat) throws MalformedURLException, IOException { Resource resource = Resource.newResource(saveat); ObjectOutputStream out = new ObjectOutputStream(resource.getOutputStream()); out.writeObject(this); out.flush(); out.close(); log.info("Saved " + this + " to " + resource); }
From source file:com.ebay.jetstream.messaging.transport.zookeeper.ZooKeeperTransport.java
void setData(JetstreamMessage msg) { if (!m_initialized.get()) { //throw new Exception("ZooKeeperTransport not initialized"); }/*ww w .ja v a2 s .co m*/ ZooKeeperDataWrapper wrapperData = new ZooKeeperDataWrapper(msg); ByteArrayOutputStream out_stream = new ByteArrayOutputStream(64000); out_stream.reset(); ObjectOutputStream out; try { out = new ObjectOutputStream(out_stream); out.writeObject(wrapperData); out.flush(); } catch (IOException e) { LOGGER.warn(e.getLocalizedMessage()); } byte buf[] = out_stream.toByteArray(); String path = prependPath(msg.getTopic().getTopicName()); String ctxtpath = getNettyContext(msg); if (ctxtpath != null) { path = path + prependPath(ctxtpath); } LOGGER.info("Topic to Send ::" + path); try { m_group.setGroupMemberData(path, buf); } catch (Throwable t) { LOGGER.warn("Exception while sending message to ZK server", t); } m_totalMsgsSent.increment(); m_msgsSentPerSec.increment(); buf = null; }
From source file:org.restcomm.app.utillib.Reporters.ReportManager.java
public void saveCurrentCarrierToStorage(Carrier carr) { String fileName = null;/*from w w w.j av a 2 s. c o m*/ if ((Environment.getExternalStorageState().toString()).equals(Environment.MEDIA_MOUNTED)) //SD card fileName = Environment.getExternalStorageDirectory().toString() + "/mmccarrier.txt"; else fileName = (mContext.getApplicationContext()).getCacheDir().toString() + "/mmccarrier.txt"; //cache if (fileName != null) { FileOutputStream fos = null; ObjectOutputStream out = null; try { fos = new FileOutputStream(fileName); if (fos != null) { out = new ObjectOutputStream(fos); out.writeObject(carr); out.flush(); out.close(); fos.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.wso2.carbon.ml.core.impl.MLModelHandler.java
private void persistModel(long modelId, String modelName, MLModel model) throws MLModelBuilderException { try {/*from w ww . j av a2s . c om*/ MLStorage storage = databaseService.getModelStorage(modelId); if (storage == null) { throw new MLModelBuilderException("Invalid model ID: " + modelId); } String storageType = storage.getType(); String storageLocation = storage.getLocation(); String outPath = storageLocation + File.separator + modelName; // if this is a deeplearning model, need to set the storage location for writing // then the sparkdeeplearning model will use ObjectTreeBinarySerializer to write it to the given directory // the DeeplearningModel will be saved as a .bin file if (MLConstants.DEEPLEARNING.equalsIgnoreCase(model.getAlgorithmClass())) { MLDeeplearningModel mlDeeplearningModel = (MLDeeplearningModel) model.getModel(); mlDeeplearningModel.setStorageLocation(storageLocation); model.setModel(mlDeeplearningModel); // Write POJO if it is a Deep Learning model // convert model name String dlModelName = modelName.replace('.', '_').replace('-', '_'); File file = new File(storageLocation + "/" + dlModelName + "_dl" + ".java"); FileOutputStream fileOutputStream = new FileOutputStream(file); DeepLearningModel deepLearningModel = mlDeeplearningModel.getDlModel(); deepLearningModel.toJava(fileOutputStream, false, false); fileOutputStream.close(); MLModel dlModel = new MLModel(); dlModel.setAlgorithmClass(model.getAlgorithmClass()); dlModel.setAlgorithmName(model.getAlgorithmName()); dlModel.setEncodings(model.getEncodings()); dlModel.setFeatures(model.getFeatures()); dlModel.setResponseIndex(model.getResponseIndex()); dlModel.setResponseVariable(model.getResponseVariable()); dlModel.setNewToOldIndicesList(model.getNewToOldIndicesList()); // Writing the DL model without Deep Learning logic // For prediction with POJO MLIOFactory ioFactoryDl = new MLIOFactory(mlProperties); MLOutputAdapter outputAdapterDl = ioFactoryDl .getOutputAdapter(storageType + MLConstants.OUT_SUFFIX); ByteArrayOutputStream baosDl = new ByteArrayOutputStream(); ObjectOutputStream oosDl = new ObjectOutputStream(baosDl); oosDl.writeObject(dlModel); oosDl.flush(); oosDl.close(); InputStream isDl = new ByteArrayInputStream(baosDl.toByteArray()); // adapter will write the model and close the stream. outputAdapterDl.write(outPath + "_dl", isDl); } MLIOFactory ioFactory = new MLIOFactory(mlProperties); MLOutputAdapter outputAdapter = ioFactory.getOutputAdapter(storageType + MLConstants.OUT_SUFFIX); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(model); oos.flush(); oos.close(); InputStream is = new ByteArrayInputStream(baos.toByteArray()); // adapter will write the model and close the stream. outputAdapter.write(outPath, is); databaseService.updateModelStorage(modelId, storageType, outPath); log.info(String.format("Successfully persisted the model [id] %s", modelId)); } catch (Exception e) { throw new MLModelBuilderException("Failed to persist the model [id] " + modelId + ". " + e.getMessage(), e); } }