List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.hoteia.qalingo.core.dao.EmailDao.java
/** * @throws IOException//from w ww . java2s . c om * @see org.hoteia.qalingo.core.dao.EmailDao#saveEmail(Email email, * MimeMessagePreparatorImpl mimeMessagePreparator) */ public Email saveEmail(final Email email, final MimeMessagePreparatorImpl mimeMessagePreparator) throws IOException { Session session = (Session) em.getDelegate(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(mimeMessagePreparator); oos.flush(); oos.close(); bos.close(); byte[] data = bos.toByteArray(); Blob blob = Hibernate.getLobCreator(session).createBlob(data); email.setEmailContent(blob); return saveOrUpdateEmail(email); }
From source file:com.mtgi.analytics.test.AbstractPerformanceTestCase.java
private byte[] serializeJob(TestProcess job) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(buf); oos.writeObject(job);/*from w w w . j av a 2s . c om*/ oos.flush(); return buf.toByteArray(); }
From source file:com.github.stephanarts.cas.ticket.registry.provider.AddMethodTest.java
@Test public void testValidInput() throws Exception { final byte[] serializedTicket; final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>(); final JSONObject params = new JSONObject(); final IMethod method = new AddMethod(map); final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud"; final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable()); when(ticket.getId()).thenReturn(ticketId); try {/*w w w .ja v a 2s . c o m*/ ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicket = bo.toByteArray(); params.put("ticket-id", ticketId); params.put("ticket", DatatypeConverter.printBase64Binary(serializedTicket)); method.execute(params); } catch (final JSONRPCException e) { Assert.fail(e.getMessage()); } catch (final Exception e) { throw new Exception(e); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.bincas.BinaryCasWriter.java
private void writeTypeSystem(JCas aJCas, OutputStream aOS) throws IOException { ObjectOutputStream typeOS = new ObjectOutputStream(aOS); CASMgrSerializer casMgrSerializer = serializeCASMgr(aJCas.getCasImpl()); typeOS.writeObject(casMgrSerializer); typeOS.flush(); }
From source file:com.sliit.rules.RuleContainer.java
private void loadSaveModel(String filePath, boolean status) { System.out.println("rule loadSaveModel"); if (status) { try {//from www . ja v a 2 s. c o m ObjectOutputStream outStream = new ObjectOutputStream(new FileOutputStream(filePath)); outStream.writeObject(ruleMoldel); outStream.flush(); outStream.close(); } catch (IOException e) { log.error("Error occurred:" + e.getMessage()); } } else { try { ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(filePath)); ruleMoldel = (JRip) inputStream.readObject(); } catch (IOException e) { log.error("Error occurred:" + e.getMessage()); } catch (ClassNotFoundException e) { log.error("Error occurred:" + e.getMessage()); } } }
From source file:edu.clemson.cs.nestbed.server.management.profiling.MoteMessageManager.java
public void messageReceived(int toAddr, Message msg) { try {//from w w w . j a va 2s . c o m String name = msg.getClass().getName(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(msg); oos.flush(); outerLoop: for (ProgramMessageSymbol i : messageObserverListMap.keySet()) { if (i.getName().equals(name)) { List<RemoteObserver> observers; observers = messageObserverListMap.get(i); for (RemoteObserver j : observers) { byte[] bytes = out.toByteArray(); out.close(); log.info(bytes.length); j.update(i.getID(), bytes); } break outerLoop; } } } catch (Exception ex) { log.error("Exception while receiving message", ex); } }
From source file:com.github.stephanarts.cas.ticket.registry.provider.AddMethodTest.java
@Test public void testDuplicateTicket() throws Exception { final byte[] serializedTicket; final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>(); final JSONObject params = new JSONObject(); final IMethod method = new AddMethod(map); final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud"; final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable()); when(ticket.getId()).thenReturn(ticketId); map.put(ticketId.hashCode(), ticket); try {// w ww . j av a2 s .c om ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicket = bo.toByteArray(); params.put("ticket-id", ticketId); params.put("ticket", DatatypeConverter.printBase64Binary(serializedTicket)); method.execute(params); } catch (final JSONRPCException e) { Assert.assertEquals(-32502, e.getCode()); Assert.assertTrue(e.getMessage().equals("Duplicate Ticket")); return; } catch (final Exception e) { throw new Exception(e); } Assert.fail("No Exception Thrown"); }
From source file:es.logongas.ix3.web.security.impl.WebSessionSidStorageImplAbstractJws.java
private String serialize(Serializable serializable) { try {/*from w ww . j a v a 2s. c om*/ Base64 base64 = new Base64(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(outputStream); so.writeObject(serializable); so.flush(); return base64.encodeAsString(outputStream.toByteArray()); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.mule.transformer.simple.SerializedMuleMessageTransformersTestCase.java
@Override public Object getResultData() { try {// w ww .j av a 2 s . c o m ByteArrayOutputStream bs; ObjectOutputStream os; bs = new ByteArrayOutputStream(); os = new ObjectOutputStream(bs); os.writeObject(testObject); os.flush(); os.close(); return bs.toByteArray(); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } }
From source file:com.limegroup.gnutella.auth.ContentCache.java
/** * Write cache so that we only have to calculate them once. *///w w w. jav a 2 s . c o m public void persistCache() { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(CACHE_FILE))); oos.writeObject(responses); oos.flush(); } catch (IOException e) { LOG.error(e); } finally { IOUtils.close(oos); } }