List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.compass.gps.device.jdbc.snapshot.FSJdbcSnapshotPersister.java
public void save(JdbcSnapshot snapshot) throws JdbcGpsDeviceException { try {/*from www .java2 s. com*/ ObjectOutputStream objStream = new ObjectOutputStream(new FileOutputStream(path)); objStream.writeObject(snapshot); objStream.flush(); objStream.close(); if (log.isDebugEnabled()) { File file = new File(path); log.debug("Saved snapshot data to [" + path + "] size [" + file.length() + "bytes]"); } } catch (IOException e) { throw new JdbcGpsDeviceException("Failed to save jdbc snapshot", e); } }
From source file:dkpro.similarity.algorithms.wikipedia.measures.WikiLinkCache.java
/** * Serializes the cache and saves it to the given file. * * @param file the file to save the cache to * @throws IOException/*from w ww .ja v a 2 s .co m*/ * @throws FileNotFoundException * @throws IOException if the file cannot be read */ public void serializeObject(Object o, File file) throws FileNotFoundException, IOException { logger.info("Writing cache to file: " + file.getAbsolutePath()); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(o); oos.flush(); oos.close(); }
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 .j a v a2s . c o m*/ 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:com.fuzhepan.arpc.client.ProxyHandler.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { log.debug("invoke was called!"); if (method.getName().equals("toString")) { return "toString method was called"; }/* w w w. ja v a 2 s. c om*/ RpcContext rpcContext = new RpcContext(interfaceName, method.getName(), method.getParameterTypes(), args); //get service info and load balance List<HostPortPair> serviceList = RpcConfig.getServiceList(serviceName); if (serviceList == null || serviceList.size() == 0) throw new ClassNotFoundException("not find service : " + serviceName); int index = requestCount.get() % serviceList.size(); if (requestCount.get() > 100) requestCount.set(0); else requestCount.getAndIncrement(); HostPortPair hostPort = serviceList.get(index); Socket socket = new Socket(hostPort.host, hostPort.port); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); objectOutputStream.writeObject(rpcContext); objectOutputStream.flush(); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); Object response = objectInputStream.readObject(); objectInputStream.close(); objectOutputStream.close(); socket.close(); Class methodReturnType = method.getReturnType(); return methodReturnType.cast(response); }
From source file:org.wso2.carbon.inbound.feedep.FeedRegistryHandler.java
private byte[] toByteArray(Object date) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos; try {/*from w w w .jav a 2 s .com*/ oos = new ObjectOutputStream(bos); oos.writeObject(date); oos.flush(); oos.close(); bos.close(); } catch (IOException e) { log.error("Error while reading the registry", e); } return bos.toByteArray(); }
From source file:org.kawanfw.sql.transport.UrlTransporter.java
/** * Transforms an URL to serialized Base 64 String. * //from w w w. ja va2s . c o m * @param url * the URL to transform * @return a serialized URL in Base64 format * @throws IOException */ public String toBase64(URL url) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(bos); oos.writeObject(url); oos.flush(); byte[] byteArray = bos.toByteArray(); String base64 = URL_HEADER + Base64.byteArrayToBase64(byteArray); return base64; } finally { if (oos != null) { oos.close(); } } }
From source file:org.versly.rest.wsdoc.RestDocumentation.java
public void toStream(OutputStream out) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(this); oos.flush(); }
From source file:common.services.generic.GenericCacheService.java
@Override public boolean saveToFile() { if (cached_object == null) return false; try {//from w ww . j a v a2s . 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:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException//from w w w. j a va 2 s . co 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:org.kuali.student.common.spring.TestWebServiceAwareBeanPostProcessorManualWithContextPostProcessor.java
private void testBeanSerialization(Object bean, String expectedToStringValue, long expectedSize) throws IOException, ClassNotFoundException { File tempFile = File.createTempFile("proxy", "dat"); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tempFile)); oos.writeObject(bean);//from ww w. ja va 2 s. co m oos.flush(); oos.close(); // check the size of that file long serializedSizeInBytes = FileUtils.sizeOf(tempFile); Assert.assertEquals(expectedSize, serializedSizeInBytes); ObjectInputStream iis = new ObjectInputStream(new FileInputStream(tempFile)); MessageService generated = (MessageService) iis.readObject(); iis.close(); Assert.assertEquals(expectedToStringValue, generated.toString()); }