List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException/*from w w w.j a v a 2 s.c o m*/ * @see fr.hoteia.qalingo.core.dao.impl.EmailDao#handleEmailException(Email email, Exception e) */ public void handleEmailException(final Email email, final Exception exception) throws IOException { Session session = (Session) em.getDelegate(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(exception); oos.flush(); oos.close(); bos.close(); byte[] data = bos.toByteArray(); Blob blob = Hibernate.getLobCreator(session).createBlob(data); email.setExceptionContent(blob); }
From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.GoogleDictionaryTest.java
@Test public void testGoogleDictionary() throws Exception { FileUtils.deleteQuietly(new File(output)); GoogleDictionary dictionary = new GoogleDictionary(path, needed_mentions); Assert.assertNotNull(dictionary);/* w w w .j a v a 2s . c om*/ ObjectOutputStream dictionaryWriter = new ObjectOutputStream( new BZip2CompressorOutputStream(new FileOutputStream(output))); dictionaryWriter.writeObject(dictionary); dictionaryWriter.close(); Assert.assertTrue(new File(output).exists()); ObjectInputStream dictionaryReader = new ObjectInputStream( new BZip2CompressorInputStream(new FileInputStream(output))); dictionary = null; dictionary = (GoogleDictionary) dictionaryReader.readObject(); Assert.assertNotNull(dictionary); System.out.println(dictionary.getNumberOfMentionEntityPairs()); System.out.println(dictionary.getTargetSize()); Assert.assertEquals(3, dictionary.getTargetValuePairs("claude_monet").size()); dictionaryReader.close(); }
From source file:edu.uci.ics.jung.visualization.layout.PersistentLayoutImpl.java
/** * save the Vertex locations to a file//w ww .j a v a 2s . c o m * @param fileName the file to save to * @throws an IOException if the file cannot be used */ public void persist(String fileName) throws IOException { for (V v : getGraph().getVertices()) { Point p = new Point(transform(v)); map.put(v, p); } ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName)); oos.writeObject(map); oos.close(); }
From source file:common.services.generic.GenericCacheService.java
@Override public boolean saveToFile() { if (cached_object == null) return false; try {// w w w. j a v a 2 s. co m File f = new File(path, "cache.tmp"); if (f.exists()) f.delete(); f.createNewFile(); FileOutputStream fo = new FileOutputStream(f); ObjectOutputStream so = new ObjectOutputStream(fo); so.writeObject(cached_object); so.flush(); so.close(); fo.close(); return true; } catch (IOException ex) { logger.error("failed to save cache path = " + path, ex); return false; } }
From source file:com.heliosapm.tsdblite.json.JSON.java
private static byte[] jserialize(final Serializable ser) { if (ser == null) return new byte[0]; ByteArrayOutputStream baos = null; ObjectOutputStream oos = null; try {/*from www.j av a2 s.c om*/ baos = new ByteArrayOutputStream(1024); oos = new ObjectOutputStream(baos); oos.writeObject(ser); oos.flush(); baos.flush(); return baos.toByteArray(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (oos != null) try { oos.close(); } catch (Exception x) { /* No Op */} if (baos != null) try { baos.close(); } catch (Exception x) { /* No Op */} } }
From source file:net.schweerelos.parrot.ui.NodeWrapperPersistentLayoutImpl.java
@Override public synchronized void persist(String fileName) throws IOException { uriToNodeLocation.clear();/* w ww . jav a 2 s. c om*/ for (NodeWrapper vertex : getGraph().getVertices()) { Point p = new Point(transform(vertex)); uriToNodeLocation.put(vertex.getOntResource().getURI(), p); } ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName)); oos.writeObject(uriToNodeLocation); oos.close(); }
From source file:org.taverna.server.master.localworker.RunDatabase.java
private void logLength(String message, Object obj) { if (!log.isDebugEnabled()) return;//w ww.j a v a 2 s . c o m try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); log.debug(message + ": " + baos.size()); } catch (Exception e) { log.warn("oops", e); } }
From source file:net.sf.dynamicreports.googlecharts.test.AbstractJasperTest.java
private JasperReportBuilder serializableTest(JasperReportBuilder report) throws IOException, ClassNotFoundException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(report);/*from ww w . ja va 2 s . c o m*/ oos.flush(); oos.close(); InputStream stream = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(stream); return (JasperReportBuilder) ois.readObject(); }
From source file:com.newrelic.agent.deps.org.apache.http.impl.client.BasicAuthCache.java
@Override public void put(final HttpHost host, final AuthScheme authScheme) { Args.notNull(host, "HTTP host"); if (authScheme == null) { return;/*from w ww.j a va 2 s .co m*/ } if (authScheme instanceof Serializable) { try { final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(buf); out.writeObject(authScheme); out.close(); this.map.put(getKey(host), buf.toByteArray()); } catch (IOException ex) { if (log.isWarnEnabled()) { log.warn("Unexpected I/O error while serializing auth scheme", ex); } } } else { if (log.isDebugEnabled()) { log.debug("Auth scheme " + authScheme.getClass() + " is not serializable"); } } }
From source file:edu.stanford.muse.lens.LensPrefs.java
private void savePrefs() { try {/*from w w w. j ava 2 s.com*/ FileOutputStream fos = new FileOutputStream(pathToPrefsFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(prefs); oos.flush(); oos.close(); PrintStream ps = new PrintStream(new FileOutputStream(pathToPrefsFile + ".txt")); for (String term : prefs.keySet()) { Map<String, Float> map = prefs.get(term); for (String url : map.keySet()) ps.println(term + "\t" + url + "\t" + map.get(url)); } ps.close(); } catch (Exception e) { e.printStackTrace(); } }