List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:com.sec.ose.osi.thread.job.identify.data.IdentifyQueue.java
private boolean updateIdentifyQueuFile() { log.debug("updateIdentifyQueFile-start - num of item:" + size()); FileOutputStream fos = null;/* w ww . j a v a 2 s.c o m*/ try { File file = new File(identifyQueueFilePath); fos = new FileOutputStream(file); if (identifyDataQueue.size() > 0) { ObjectOutputStream oosWriter = new ObjectOutputStream(fos); for (IdentifyData tmpIdentifiedData : identifyDataQueue) { oosWriter.writeObject(tmpIdentifiedData); } oosWriter.flush(); oosWriter.close(); } } catch (IOException e) { log.warn(e); } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { log.debug(e); } } log.debug("updateIdentifyQueFile-end"); } return true; }
From source file:org.wso2.carbon.identity.application.authentication.framework.store.SessionDataStore.java
private void setBlobObject(PreparedStatement prepStmt, Object value, int index) throws SQLException, IOException { if (value != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(value);//from w w w . j av a2 s . c o m oos.flush(); oos.close(); InputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); prepStmt.setBinaryStream(index, inputStream, inputStream.available()); } else { prepStmt.setBinaryStream(index, null, 0); } }
From source file:org.sventon.cache.direntrycache.CompassDirEntryCache.java
/** * @throws CacheException if unable to save revision number. *///from www. j av a 2 s . c o m private void saveLatestRevisionNumber() throws CacheException { logger.info("Saving file to disk, " + latestCachedRevisionFile); ObjectOutputStream out = null; try { out = new ObjectOutputStream(new FileOutputStream(latestCachedRevisionFile)); out.writeLong(getLatestCachedRevisionNumber()); out.flush(); out.close(); } catch (IOException ioex) { throw new CacheException("Unable to store file to disk", ioex); } finally { IOUtils.closeQuietly(out); } }
From source file:org.review_board.ereviewboard.core.ReviewboardClientManager.java
void writeCache() { ObjectOutputStream out = null; try {//from www . j av a 2 s . c o m out = new ObjectOutputStream(new FileOutputStream(cacheFile)); out.writeInt(dataByUrl.size()); for (Entry<String, ReviewboardClientData> entry : dataByUrl.entrySet()) { out.writeObject(entry.getKey()); out.writeObject(entry.getValue()); } out.flush(); } catch (IOException e) { logWarning("The Reviewboard respository data cache could not be written", e); } catch (RuntimeException e) { logWarning("The Reviewboard respository data cache could not be written", e); } finally { IOUtils.closeQuietly(out); } }
From source file:com.openteach.diamond.repository.client.cache.FileLRUCache.java
/** * //from w w w . jav a2 s . co m */ private void sync() { ObjectOutputStream out = null; try { out = new ObjectOutputStream(new FileOutputStream(ctrlFile)); out.writeObject(new Ctrl(offset, indexStore.values(), frees)); out.flush(); } catch (IOException e) { logger.error(String.format("Wrtie ctr file:%s failed", ctrlFile.getAbsolutePath()), e); } finally { if (null != out) { try { out.close(); } catch (IOException e) { } } } }
From source file:de.ailis.oneinstance.OneInstance.java
/** * Runs the client./*from ww w .ja v a 2 s.c o m*/ * * @param socket * The client socket. * @param args * The command-line arguments. * @return True if server accepted the new instance, false if not. * @throws IOException * When communication with the server fails. */ private boolean runClient(Socket socket, String[] args) throws IOException { // Send serialized command-line argument list to the server. ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(new File(".").getCanonicalFile()); out.writeObject(args); out.flush(); // Read response from server BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); String response = in.readLine(); // If response is "exit" then don't start new instance. Any other // reply will allow the new instance. return response == null || !response.equals("exit"); }
From source file:org.kepler.objectmanager.repository.RepositoryManager.java
/** * Serialize the remote save repository name to a file on disk so it can be * loaded the next time Kepler starts./*from w w w .j av a 2s . c o m*/ */ private void serializeRemoteSaveRepo() { if (isDebugging) log.debug("serializeRemoteSaveRepo()"); File remoteSaveRepoFile = new File(_remoteSaveRepoFileName); if (remoteSaveRepoFile.exists()) { if (isDebugging) log.debug("delete " + remoteSaveRepoFile); remoteSaveRepoFile.delete(); } if (_saveRepositoryName != null) { try { OutputStream os = new FileOutputStream(remoteSaveRepoFile); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(os); oos.writeObject(_saveRepositoryName); oos.flush(); if (isDebugging) { log.debug("wrote " + remoteSaveRepoFile); } } finally { if (oos != null) { oos.close(); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.joliciel.talismane.extensions.corpus.PosTaggerStatistics.java
@Override public void onCompleteAnalysis() { try {/*w w w. j a va 2s . com*/ if (writer != null) { PosTagSet posTagSet = talismaneSession.getPosTagSet(); for (PosTag posTag : posTagSet.getTags()) { if (!posTagCounts.containsKey(posTag.getCode())) { posTagCounts.put(posTag.getCode(), 0); } } double unknownLexiconPercent = 1; if (referenceWords != null) { int unknownLexiconCount = 0; for (String word : words) { if (!referenceWords.contains(word)) unknownLexiconCount++; } unknownLexiconPercent = (double) unknownLexiconCount / (double) words.size(); } double unknownLowercaseLexiconPercent = 1; if (referenceLowercaseWords != null) { int unknownLowercaseLexiconCount = 0; for (String lowercase : lowerCaseWords) { if (!referenceLowercaseWords.contains(lowercase)) unknownLowercaseLexiconCount++; } unknownLowercaseLexiconPercent = (double) unknownLowercaseLexiconCount / (double) lowerCaseWords.size(); } writer.write(CSV.format("sentenceCount") + CSV.format(sentenceCount) + "\n"); writer.write(CSV.format("sentenceLengthMean") + CSV.format(sentenceLengthStats.getMean()) + "\n"); writer.write(CSV.format("sentenceLengthStdDev") + CSV.format(sentenceLengthStats.getStandardDeviation()) + "\n"); writer.write(CSV.format("lexiconSize") + CSV.format(words.size()) + "\n"); writer.write( CSV.format("lexiconUnknownInRefCorpus") + CSV.format(unknownLexiconPercent * 100.0) + "\n"); writer.write(CSV.format("tokenCount") + CSV.format(tokenCount) + "\n"); double unknownTokenPercent = ((double) unknownTokenCount / (double) tokenCount) * 100.0; writer.write(CSV.format("tokenUnknownInRefCorpus") + CSV.format(unknownTokenPercent) + "\n"); double unknownInLexiconPercent = ((double) unknownInLexiconCount / (double) tokenCount) * 100.0; writer.write(CSV.format("tokenUnknownInRefLexicon") + CSV.format(unknownInLexiconPercent) + "\n"); writer.write(CSV.format("lowercaseLexiconSize") + CSV.format(lowerCaseWords.size()) + "\n"); writer.write(CSV.format("lowercaseLexiconUnknownInRefCorpus") + CSV.format(unknownLowercaseLexiconPercent * 100.0) + "\n"); writer.write(CSV.format("alphanumericCount") + CSV.format(alphanumericCount) + "\n"); double unknownAlphanumericPercent = ((double) unknownAlphanumericCount / (double) alphanumericCount) * 100.0; writer.write(CSV.format("alphaUnknownInRefCorpus") + CSV.format(unknownAlphanumericPercent) + "\n"); double unknownAlphaInLexiconPercent = ((double) unknownAlphaInLexiconCount / (double) alphanumericCount) * 100.0; writer.write( CSV.format("alphaUnknownInRefLexicon") + CSV.format(unknownAlphaInLexiconPercent) + "\n"); writer.write(CSV.format("openClassCount") + CSV.format(openClassCount) + "\n"); double openClassUnknownPercent = ((double) openClassUnknownInRefCorpus / (double) openClassCount) * 100.0; writer.write( CSV.format("openClassUnknownInRefCorpus") + CSV.format(openClassUnknownPercent) + "\n"); double openClassUnknownInLexiconPercent = ((double) openClassUnknownInLexicon / (double) openClassCount) * 100.0; writer.write(CSV.format("openClassUnknownInRefLexicon") + CSV.format(openClassUnknownInLexiconPercent) + "\n"); writer.write(CSV.format("closedClassCount") + CSV.format(closedClassCount) + "\n"); double closedClassUnknownPercent = ((double) closedClassUnknownInRefCorpus / (double) closedClassCount) * 100.0; writer.write( CSV.format("closedClassUnknownInRefCorpus") + CSV.format(closedClassUnknownPercent) + "\n"); double closedClassUnknownInLexiconPercent = ((double) closedClassUnknownInLexicon / (double) closedClassCount) * 100.0; writer.write(CSV.format("closedClassUnknownInRefLexicon") + CSV.format(closedClassUnknownInLexiconPercent) + "\n"); for (String posTag : posTagCounts.keySet()) { int count = posTagCounts.get(posTag); writer.write(CSV.format(posTag) + CSV.format(count) + CSV.format(((double) count / (double) tokenCount) * 100.0) + "\n"); } writer.flush(); writer.close(); } if (this.serializationFile != null) { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(serializationFile, false)); zos.putNextEntry(new ZipEntry("Contents.obj")); ObjectOutputStream oos = new ObjectOutputStream(zos); try { oos.writeObject(this); } finally { oos.flush(); } zos.flush(); zos.close(); } } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:com.floreantpos.model.MenuItem.java
public MenuItem clone(MenuItem source) throws Exception { MenuItem menuItem = null;// w w w .ja va 2 s .c o m try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(source); out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); menuItem = (MenuItem) in.readObject(); in.close(); } catch (Exception ex) { throw ex; } return menuItem; }