List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException//from w ww . j a v a 2s.co m * @see fr.hoteia.qalingo.core.dao.impl.EmailDao#saveEmail(Email email, * MimeMessagePreparatorImpl mimeMessagePreparator) */ public void 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); saveOrUpdateEmail(email); }
From source file:net.mindengine.oculus.frontend.web.controllers.report.ReportBrowseSaveCollectedRunsController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Session session = Session.create(request); String name = request.getParameter("saveName"); String redirect = request.getParameter("redirect"); if (redirect == null) { redirect = ""; }/*w w w . ja v a2s .c om*/ User user = Auth.getAuthorizedUser(request); if (user == null) throw new NotAuthorizedException(); List<TestRunSearchData> collectedTestRuns = session.getCollectedTestRuns(); SavedRun savedRun = new SavedRun(); savedRun.setDate(new Date()); savedRun.setName(name); savedRun.setUserId(user.getId()); Long id = testRunDAO.saveRun(savedRun); savedRun.setId(id); FileUtils.mkdirs(config.getDataFolder() + File.separator + savedRun.generateDirUrl()); File file = new File(config.getDataFolder() + File.separator + savedRun.generateFileUrl()); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(collectedTestRuns); oos.flush(); oos.close(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String strDate = sdf.format(savedRun.getDate()); String convertedName = savedRun.getName().replaceAll("[^a-zA-Z0-9]", "_"); String url = "../report/saved-" + user.getLogin() + "-" + strDate + "-" + convertedName + "-" + id; session.setTemporaryMessage("Your collected test runs were successfully saved." + " You can use them with the following url:<br/>" + "HTML: <a href=\"" + url + ".html\">Html version</a>" + "<br/>" + "Excel: <a href=\"" + url + ".xls\">Excel version</>"); return new ModelAndView(new RedirectView(redirect)); }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.annotator.EmbeddingsCachePreprocessor.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try {//from w w w. ja v a2s. c o m Word2VecReader reader = new Word2VecReader(word2VecFile, true); String[] tokenArray = new ArrayList<>(tokens).toArray(new String[tokens.size()]); System.out.println("Vocabulary size: " + tokenArray.length); Embedding[] embeddings = reader.getEmbeddings(tokenArray); Map<String, no.uib.cipr.matrix.Vector> cache = new HashMap<>(); if (tokenArray.length != embeddings.length) { throw new IllegalStateException(); } for (int i = 0; i < tokenArray.length; i++) { String token = tokenArray[i]; Embedding embedding = embeddings[i]; if (embedding != null) { cache.put(token, embedding.getVector()); } else { cache.put(token, null); } } FileOutputStream fos = new FileOutputStream(cacheFile); ObjectOutputStream os = new ObjectOutputStream(fos); os.writeObject(cache); IOUtils.closeQuietly(fos); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
From source file:org.sample.readerwriter.MyWriter.java
@Override public void writeTo(MyObject t, Class<?> type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap<String, Object> mm, OutputStream out) throws IOException, WebApplicationException { ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(t);/* w w w. j a va 2 s . c o m*/ }
From source file:SerializationUtils.java
/** * <p>Serializes an <code>Object</code> to the specified stream.</p> * * <p>The stream will be closed once the object is written. * This avoids the need for a finally clause, and maybe also exception * handling, in the application code.</p> * /*from www . ja v a 2s . c o m*/ * <p>The stream passed in is not buffered internally within this method. * This is the responsibility of your application if desired.</p> * * @param obj the object to serialize to bytes, may be null * @param outputStream the stream to write to, must not be null * @throws IllegalArgumentException if <code>outputStream</code> is <code>null</code> * @throws SerializationException (runtime) if the serialization fails */ public static void serialize(Serializable obj, OutputStream outputStream) { if (outputStream == null) { throw new IllegalArgumentException("The OutputStream must not be null"); } ObjectOutputStream out = null; try { // stream closed in the finally out = new ObjectOutputStream(outputStream); out.writeObject(obj); } catch (IOException ex) { throw new RuntimeException(ex); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { // ignore close exception } } }
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 v a2 s . com*/ 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:com.gsma.mobileconnect.discovery.DiscoveryResponseTest.java
private DiscoveryResponse roundTripSerialize(DiscoveryResponse in) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(baos); output.writeObject(in);/*w w w .java 2s . c o m*/ output.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInput input = new ObjectInputStream(bais); DiscoveryResponse out = (DiscoveryResponse) input.readObject(); input.close(); return out; }
From source file:RedisCache.java
/** Write the object to a Base64 string. */ private static String toString(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);//from w w w . ja va2 s. c om oos.close(); return new String(Base64.encodeBase64(baos.toByteArray())); }
From source file:edu.uci.ics.jung.visualization.layout.PersistentLayoutImpl.java
/** * save the Vertex locations to a file//from w ww . j ava 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:net.sf.farrago.server.FarragoServletCommandSink.java
private void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException { ObjectInputStream ois = null; ObjectOutputStream oos = null; try {//from w ww . j av a2s . co m // Get the method to execute String method = httpServletRequest.getHeader(ServletCommandSinkIdentifier.METHOD_IDENTIFIER); if (method != null) { ois = new ObjectInputStream(httpServletRequest.getInputStream()); // And initialize the output OutputStream os = httpServletResponse.getOutputStream(); oos = new ObjectOutputStream(os); Object objectToReturn = null; try { // Some command to process ? if (method.equals(ServletCommandSinkIdentifier.PROCESS_COMMAND)) { // Read parameter objects Long connuid = (Long) ois.readObject(); Long uid = (Long) ois.readObject(); Command cmd = (Command) ois.readObject(); CallingContext ctx = (CallingContext) ois.readObject(); // Delegate execution to the CommandProcessor objectToReturn = processor.process(connuid, uid, cmd, ctx); } else if (method.equals(ServletCommandSinkIdentifier.CONNECT_COMMAND)) { String url = ois.readUTF(); Properties props = (Properties) ois.readObject(); Properties clientInfo = (Properties) ois.readObject(); CallingContext ctx = (CallingContext) ois.readObject(); ConnectionConfiguration connectionConfiguration = VJdbcConfiguration.singleton() .getConnection(url); if (connectionConfiguration != null) { Connection conn = connectionConfiguration.create(props); objectToReturn = processor.registerConnection(conn, connectionConfiguration, clientInfo, ctx); } else { objectToReturn = new SQLException("VJDBC-Connection " + url + " not found"); } } } catch (Throwable t) { // Wrap any exception so that it can be transported back to // the client objectToReturn = SQLExceptionHelper.wrap(t); } // Write the result in the response buffer oos.writeObject(objectToReturn); oos.flush(); httpServletResponse.flushBuffer(); } else { // No VJDBC-Method ? Then we redirect the stupid browser user to // some information page :-) httpServletResponse.sendRedirect("index.html"); } } catch (Exception e) { logger.error("Unexpected Exception", e); throw new ServletException(e); } finally { StreamCloser.close(ois); StreamCloser.close(oos); } }