List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * Save the reminder data./*from www .jav a 2s .c o m*/ */ public synchronized void store() { try { String userDirectoryName = Settings.getUserSettingsDirName(); File userDirectory = new File(userDirectoryName); File tmpDatFile = new File(userDirectory, DATAFILE_NAME + ".temp"); File datFile = new File(userDirectory, DATAFILE_NAME); StreamUtilities.objectOutputStream(tmpDatFile, new ObjectOutputStreamProcessor() { public void process(ObjectOutputStream out) throws IOException { writeData(out); out.flush(); out.close(); } }); datFile.delete(); tmpDatFile.renameTo(datFile); } catch (IOException e) { ErrorHandler.handle("Could not store reminder data.", e); } try { mConfigurationHandler.storeSettings(mSettings); } catch (IOException e) { ErrorHandler.handle("Could not store reminder settings.", e); } }
From source file:com.hackensack.umc.activity.ProfileActivity.java
private void saveCardResponse(ArrayList<CardResponse> cardResponse1) { try {// w w w .j a va 2 s . c o m ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(new File(Constant.CARD_RESPONSE_FILE_PATH))); //Select where you wish to save the file... oos.writeObject(cardResponse1); oos.flush(); oos.close(); } catch (Exception ex) { Log.v("Address Book", ex.getMessage()); ex.printStackTrace(); } }
From source file:com.ibuildapp.romanblack.NewsPlugin.NewsPlugin.java
/** * Async loading and parsing RSS feed./*from w w w . j a va 2 s . c o m*/ */ private void loadRSS() { try {//ErrorLogging new Thread() { @Override public void run() { // parsing FeedParser reader = new FeedParser(feedURL); items = reader.parseFeed(); if (items.size() > 0) { File cache = new File(cachePath); File[] files = cache.listFiles(); for (File file : files) { if (!file.getName().equals("cache.md5")) file.delete(); } try { ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(cachePath + "/cache.data")); oos.writeObject(items); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); } } for (int i = 0; i < items.size(); i++) { items.get(i).setTextColor(widget.getTextColor()); items.get(i).setDateFormat(widget.getDateFormat()); } runOnUiThread(new Runnable() { @Override public void run() { refreshLayout.setRefreshing(false); } }); selectShowType(); } }.start(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.kepler.objectmanager.cache.CacheManager.java
private void serializeObjectInFile(CacheObjectInterface co, String filename) throws CacheException { File outputFile = new File(""); try {//w w w . java 2s . c om outputFile = new File(CacheManager.objectPath, filename); if (isDebugging) log.debug(outputFile.toString()); FileOutputStream fos = new FileOutputStream(outputFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(co); // serialize the CacheObjectInterface itself oos.flush(); oos.close(); } catch (IOException e) { log.error("Serializing object to cache has failed: " + outputFile.toString()); e.printStackTrace(); throw new CacheException("Unable to serialize " + co.getName(), e); } }
From source file:org.apache.jcs.auxiliary.disk.block.BlockDiskKeyStore.java
/** * Saves key file to disk. This gets the LRUMap entry set and write the entries out one by one * after putting them in a wrapper.//from ww w.j a va 2s .c o m */ protected void saveKeys() { try { ElapsedTimer timer = new ElapsedTimer(); int numKeys = keyHash.size(); if (log.isInfoEnabled()) { log.info(logCacheName + "Saving keys to [" + this.keyFile.getAbsolutePath() + "], key count [" + numKeys + "]"); } keyFile.delete(); keyFile = new File(rootDirectory, fileName + ".key"); FileOutputStream fos = new FileOutputStream(keyFile); BufferedOutputStream bos = new BufferedOutputStream(fos, 1024); ObjectOutputStream oos = new ObjectOutputStream(bos); try { // don't need to synchronize, since the underlying collection makes a copy Iterator keyIt = keyHash.entrySet().iterator(); while (keyIt.hasNext()) { Map.Entry entry = (Map.Entry) keyIt.next(); BlockDiskElementDescriptor descriptor = new BlockDiskElementDescriptor(); descriptor.setKey((Serializable) entry.getKey()); descriptor.setBlocks((int[]) entry.getValue()); // stream these out in the loop. oos.writeObject(descriptor); } } finally { oos.flush(); oos.close(); } if (log.isInfoEnabled()) { log.info(logCacheName + "Finished saving keys. It took " + timer.getElapsedTimeString() + " to store " + numKeys + " keys. Key file length [" + keyFile.length() + "]"); } } catch (Exception e) { log.error(logCacheName + "Problem storing keys.", e); } }
From source file:org.apache.openjpa.event.TCPRemoteCommitProvider.java
public void broadcast(RemoteCommitEvent event) { try {/*w w w . j a v a2 s .c om*/ // build a packet notifying other JVMs of object changes. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeLong(PROTOCOL_VERSION); oos.writeLong(_id); oos.writeInt(_port); oos.writeObject(_localhost); oos.writeObject(event); oos.flush(); byte[] bytes = baos.toByteArray(); baos.close(); if (_broadcastThreads.isEmpty()) sendUpdatePacket(bytes); else _broadcastQueue.addPacket(bytes); } catch (IOException ioe) { if (log.isWarnEnabled()) log.warn(s_loc.get("tcp-payload-create-error"), ioe); } }
From source file:org.hyperic.hq.agent.server.AgentDListProvider.java
public void saveObject(Object obj, String objectName) { File file = new File(this.writeDir + System.getProperty("file.separator") + objectName); ObjectOutputStream outputStream = null; try {/* w w w. jav a2 s .c om*/ outputStream = new ObjectOutputStream(new FileOutputStream(file)); outputStream.writeObject(obj); } catch (Exception ex) { log.error("Cannot save object '" + objectName + "'", ex); } finally { try { if (outputStream != null) { outputStream.flush(); outputStream.close(); } } catch (IOException ex) { log.error(ex); } } }
From source file:com.iorga.webappwatcher.EventLogManager.java
private void writeEventLog(final EventLog eventLog) throws FileNotFoundException, IOException, InterruptedException { if (!eventLog.isCompleted()) { log.info("Writing not completed " + eventLog.getClass().getName() + "#" + eventLog.getDate().getTime()); }/* www .ja v a 2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("Writing " + eventLog.toString()); } synchronized (objectOutputStreamLogLock) { final ObjectOutputStream objectOutputStream = getOrOpenLog(); objectOutputStream.writeObject(eventLog); eventsWritten++; if (eventsWritten % 1000 == 0) { // every 1000 events, reset the outputstream in order to read it without requiring plenty of memory objectOutputStream.reset(); } if (eventsWritten % 50 == 0) { // every 100 events written, let's flush & check if the file size is more than the max authorized objectOutputStream.flush(); if (getEventLogLength() > maxLogFileSizeMo * 1024 * 1024) { closeLog(); } } } }
From source file:com.limegroup.gnutella.xml.LimeXMLReplyCollection.java
/** Serializes the current map to disk. */ public boolean writeMapToDisk() { boolean wrote = false; Map<FileAndUrn, String> xmlMap; synchronized (LOCK) { if (!dirty) { LOG.debug("Not writing because not dirty."); return true; }//from www . j av a 2 s . c o m xmlMap = new HashMap<FileAndUrn, String>(mainMap.size()); for (Map.Entry<FileAndUrn, LimeXMLDocument> entry : mainMap.entrySet()) xmlMap.put(entry.getKey(), ((GenericXmlDocument) entry.getValue()).getXmlWithVersion()); dirty = false; } File dataFile = new File(savedDocsDir, LimeXMLSchema.getDisplayString(schemaURI) + ".sxml3"); File parent = dataFile.getParentFile(); if (parent != null) parent.mkdirs(); ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile))); out.writeObject(xmlMap); out.flush(); wrote = true; } catch (IOException ignored) { LOG.trace("Unable to write", ignored); } finally { IOUtils.close(out); } return wrote; }
From source file:org.apache.james.queue.file.FileMailQueue.java
@Override public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException { final String key = mail.getName() + "-" + COUNTER.incrementAndGet(); FileOutputStream out = null;// w w w. j a v a 2s.com FileOutputStream foout = null; ObjectOutputStream oout = null; try { int i = (int) (Math.random() * SPLITCOUNT + 1); String name = queueDirName + "/" + i + "/" + key; final FileItem item = new FileItem(name + OBJECT_EXTENSION, name + MSG_EXTENSION); if (delay > 0) { mail.setAttribute(NEXT_DELIVERY, System.currentTimeMillis() + unit.toMillis(delay)); } foout = new FileOutputStream(item.getObjectFile()); oout = new ObjectOutputStream(foout); oout.writeObject(mail); oout.flush(); if (sync) foout.getFD().sync(); out = new FileOutputStream(item.getMessageFile()); mail.getMessage().writeTo(out); out.flush(); if (sync) out.getFD().sync(); keyMappings.put(key, item); if (delay > 0) { // The message should get delayed so schedule it for later scheduler.schedule(new Runnable() { @Override public void run() { try { inmemoryQueue.put(key); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Unable to init", e); } } }, delay, unit); } else { inmemoryQueue.put(key); } //TODO: Think about exception handling in detail } catch (FileNotFoundException e) { throw new MailQueueException("Unable to enqueue mail", e); } catch (IOException e) { throw new MailQueueException("Unable to enqueue mail", e); } catch (MessagingException e) { throw new MailQueueException("Unable to enqueue mail", e); } catch (InterruptedException e) { throw new MailQueueException("Unable to enqueue mail", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // ignore on close } } if (oout != null) { try { oout.close(); } catch (IOException e) { // ignore on close } } if (foout != null) { try { foout.close(); } catch (IOException e) { // ignore on close } } } }