List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.nuxeo.ecm.core.redis.contribs.RedisWorkQueuing.java
protected byte[] serializeWork(Work work) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baout); out.writeObject(work);/*from w ww. jav a2 s . com*/ out.flush(); out.close(); return baout.toByteArray(); }
From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java
private void writeProtocol(ObjectOutputStream out, URI uri, RemoteRemoteObject rro) throws IOException { String scheme = uri.getScheme(); byte[] buf = null; ObjectOutputStream oos = null; try {/*from ww w . j a v a2 s.c o m*/ RemoteObjectFactory rof = AbstractRemoteObjectFactory.getRemoteObjectFactory(scheme); ByteArrayOutputStream baos = new ByteArrayOutputStream(); oos = rof.getProtocolObjectOutputStream(baos); oos.writeObject(rro); oos.flush(); buf = baos.toByteArray(); } catch (UnknownProtocolException e) { LOGGER_RO.warn("[ROAdapter] Failed to serialize the RemoteRemoteObject for " + uri); } finally { if (oos != null) oos.close(); } out.writeObject(uri); out.writeObject(buf); // null if serialization failed }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.DispatchServ.java
/** TCP: This method opens up a ServerSocket at the given port then starts a thread that waits * for TCPMonitorReceivers to attempt to connect. Each connecting TCPMonitorReceiver creates an * individual Socket connection, which is then attached to a TCPMonitorTransmitter. The MonitorServ * uses the transmitter to communicate with the receiver, which in turn manipulates the monitor. *///from w ww . j a v a 2 s. c o m private int activateTCPMonitorTunnel(int port) { try { log.info("DispatchServ is creating a TCP ServerSocket on port " + port + " for use in server-monitor communication"); servSock = new ServerSocket(port); Runnable registrar = new Runnable() { public void run() { while (!stopRegThread) { try { monitorSocket = servSock.accept(); log.debug( "Communication socket accepted from new monitor, opening input/output streams..."); ObjectInputStream inputStream = new ObjectInputStream(monitorSocket.getInputStream()); ObjectOutputStream outputStream = new ObjectOutputStream( monitorSocket.getOutputStream()); outputStream.flush(); log.debug("Input stream opened, reading session ID from connecting monitor"); int sessionId = inputStream.readInt(); log.debug("Session ID " + sessionId + " read from new monitor socket, pairing TCP receiver with a transmitter"); MonitorTransmitter transmitter = new TCPMonitorTransmitter(monitorSocket, inputStream, outputStream); registerMonitorTransmitter(transmitter, sessionId); } catch (Exception e) { log.warn( "Error while accepting a monitor socket connection -- returning to 'waiting for accept' state", e); System.out.println( "Error while accepting a monitor socket connection -- returning to 'waiting for accept' state"); e.printStackTrace(); continue; } } /*log.error("exited while loop"); try{ monitorSocket.close(); } catch( IOException ioe ){ log.warn("Error while trying to close monitorSocket"); ioe.printStackTrace(); }*/ } }; registrationThread = new Thread(registrar); registrationThread.setDaemon(true); registrationThread.start(); return port; } catch (Exception re) { log.error("Error activating ServerSocket for use in TCP monitor communication", re); return OPERATION_FAILED; } }
From source file:org.jahia.utils.maven.plugin.contentgenerator.wise.FileAndFolderService.java
private List<FolderBO> generateFolders(Integer currentDepth, String currentPath, String currentNodePath, ExportBO wiseExport) {/*ww w . j a va2 s.c o m*/ Integer nbFoldersPerLevel = wiseExport.getNbFoldersPerLevel(); Integer foldersDepth = wiseExport.getFoldersDepth(); Integer filesPerFolder = wiseExport.getNbFilesPerFolder(); List<String> fileNames = wiseExport.getFileNames(); File filesDirectory = wiseExport.getFilesDirectory(); String depthName; switch (currentDepth) { case 1: depthName = "aaa"; break; case 2: depthName = "bbb"; break; case 3: depthName = "ccc"; break; case 4: depthName = "ddd"; break; case 5: depthName = "eee"; break; case 6: depthName = "fff"; break; case 7: depthName = "ggg"; break; case 8: depthName = "hhh"; break; case 9: depthName = "iii"; break; default: depthName = "aaa"; break; } List<FolderBO> folders = new ArrayList<FolderBO>(); for (int i = 1; i <= nbFoldersPerLevel; i++) { if (currentDepth == 1) { logger.info("Generating top folder " + i + "/" + nbFoldersPerLevel); } List<FolderBO> subFolders = null; Set<FileBO> files = generateFiles(filesPerFolder, currentNodePath + "/" + depthName + i, fileNames, wiseExport.getNumberOfUsers(), filesDirectory, wiseExport.getTags(), wiseExport.getSiteKey()); // we serialize all generated files to use them in the collections FileOutputStream tmpFile; ObjectOutputStream oos; File tmpWiseFilesDir = new File(ExportBO.tmp + sep + ContentGeneratorCst.TMP_DIR_WISE_FILES); for (FileBO file : files) { try { tmpFile = new FileOutputStream(tmpWiseFilesDir + sep + totalGeneratedFiles + ".ser"); oos = new ObjectOutputStream(tmpFile); oos.writeObject(file); oos.flush(); oos.close(); totalGeneratedFiles = totalGeneratedFiles + 1; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (currentDepth < foldersDepth) { subFolders = generateFolders(currentDepth + 1, currentPath + sep + depthName + i, currentNodePath + "/" + depthName + i, wiseExport); } FolderBO folder = new FolderBO(depthName + i, subFolders, files); folders.add(folder); if (currentDepth == 1) { File tmpTopFoldersDir = new File(ExportBO.tmp + sep + ContentGeneratorCst.TMP_DIR_TOP_FOLDERS); try { tmpFile = new FileOutputStream(tmpTopFoldersDir + sep + i + ".ser"); oos = new ObjectOutputStream(tmpFile); oos.writeObject(folder); oos.flush(); oos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } folder = null; } // create physical folder File newFolder = new File(currentPath + sep + depthName + i); newFolder.mkdirs(); // copy files into the new folder for (Iterator<FileBO> iterator = files.iterator(); iterator.hasNext();) { FileBO fileBO = (FileBO) iterator.next(); File sourceFile = new File(filesDirectory + sep + fileBO.getFileName()); File targetDirectory = new File(newFolder + sep + fileBO.getFileName()); // each file is contained in its own directory targetDirectory.mkdir(); File targetFile = new File(targetDirectory + sep + fileBO.getFileName()); try { FileUtils.copyFile(sourceFile, targetFile); } catch (IOException e) { e.printStackTrace(); } } } Collections.sort(folders); return folders; }
From source file:org.intermine.web.search.ClassAttributes.java
private static void writeObjectToDB(ObjectStore os, String key, Object object) throws IOException, SQLException { LOG.info("Saving stream to database..."); Database db = ((ObjectStoreInterMineImpl) os).getDatabase(); LargeObjectOutputStream streamOut = MetadataManager.storeLargeBinary(db, key); GZIPOutputStream gzipStream = new GZIPOutputStream(new BufferedOutputStream(streamOut)); ObjectOutputStream objectStream = new ObjectOutputStream(gzipStream); LOG.info("GZipping and serializing object..."); objectStream.writeObject(object);/*from w w w . jav a 2s.co m*/ objectStream.flush(); gzipStream.finish(); gzipStream.flush(); streamOut.close(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.frontdesk.web.data.SessionBean.java
/** * Connect to the JMarkets server and start the session defined by the given SessionDef object. * Return the session Id of the created session *///ww w .j a va2s .co m private int executeSession(String path, String name, SessionDef session) { try { URL servlet = new URL(path + "/servlet/ServletReceiver"); Request req = new Request(Request.SERVER_INIT_REQUEST); req.addIntInfo("numClients", numSubjects); req.addIntInfo("updateProtocol", JMConstants.HTTP_UPDATE_PROTOCOL); req.addIntInfo("updateTime", 100); req.addStringInfo("name", name); req.addInfo("session", session); URLConnection servletConnection = servlet.openConnection(); servletConnection.setDoInput(true); servletConnection.setDoOutput(true); servletConnection.setUseCaches(false); servletConnection.setDefaultUseCaches(false); servletConnection.setRequestProperty("Content-Type", "application/octet-stream"); ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream()); outputToServlet.writeObject(req); outputToServlet.flush(); outputToServlet.close(); ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream()); Response res = (Response) inputFromServlet.readObject(); int sessionId = res.getIntInfo("sessionId"); inputFromServlet.close(); return sessionId; } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return -1; }
From source file:org.apache.catalina.cluster.session.DeltaManager.java
private byte[] unloadDeltaRequest(DeltaRequest deltaRequest) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); deltaRequest.writeExternal(oos);//from w ww. jav a 2 s. c om oos.flush(); oos.close(); return bos.toByteArray(); }
From source file:org.wso2.carbon.cluster.coordinator.rdbms.RDBMSCommunicationBusContextImpl.java
@Override public void insertRemovedNodeDetails(String removedMember, String groupId, List<String> clusterNodes, Map<String, Object> removedPropertiesMap) throws ClusterCoordinationException { Connection connection = null; PreparedStatement storeRemovedMembersPreparedStatement = null; String task = "Storing removed member: " + removedMember + " in group " + groupId; try {//from w w w . jav a2 s. com connection = getConnection(); storeRemovedMembersPreparedStatement = connection .prepareStatement(RDBMSConstants.PS_INSERT_REMOVED_MEMBER_DETAILS); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(removedPropertiesMap); objectOutputStream.flush(); byteArrayOutputStream.flush(); objectOutputStream.close(); byteArrayOutputStream.close(); byte[] propertiesMapAsBytes = byteArrayOutputStream.toByteArray(); // ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(propertiesMapAsBytes); for (String clusterNode : clusterNodes) { storeRemovedMembersPreparedStatement.setString(1, clusterNode); storeRemovedMembersPreparedStatement.setString(2, groupId); storeRemovedMembersPreparedStatement.setString(3, removedMember); storeRemovedMembersPreparedStatement.setBinaryStream(4, new ByteArrayInputStream(propertiesMapAsBytes)); storeRemovedMembersPreparedStatement.addBatch(); } storeRemovedMembersPreparedStatement.executeBatch(); connection.commit(); } catch (SQLException e) { rollback(connection, task); throw new ClusterCoordinationException( "Error storing removed member: " + removedMember + " in group " + groupId, e); } catch (IOException e) { throw new ClusterCoordinationException("Error while inserting removed node data", e); } finally { close(storeRemovedMembersPreparedStatement, task); close(connection, task); } }
From source file:org.ejbca.core.ejb.approval.ApprovalSessionBean.java
@Override public void setApprovals(ApprovalData approvalData, final Collection<Approval> approvals) { try {/*from w ww .j ava2 s. co m*/ final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final int size = approvals.size(); oos.writeInt(size); final Iterator<Approval> iter = approvals.iterator(); while (iter.hasNext()) { final Approval next = iter.next(); oos.writeObject(next); } oos.flush(); approvalData.setApprovaldata(new String(Base64.encode(baos.toByteArray(), false))); } catch (IOException e) { log.error("Error building approvals.", e); throw new RuntimeException(e); } }
From source file:com.octo.captcha.engine.bufferedengine.buffer.DiskCaptchaBuffer.java
/** * Writes the Index to disk on shutdown <p/>The index consists of the elements Map and the freeSpace List <p/>Note * that the cache is locked for the entire time that the index is being written *///from ww w. j av a2 s .c om private synchronized void writeIndex() throws IOException { ObjectOutputStream objectOutputStream = null; try { FileOutputStream fout = new FileOutputStream(indexFile); objectOutputStream = new ObjectOutputStream(fout); objectOutputStream.writeObject(diskElements); objectOutputStream.writeObject(freeSpace); } finally { if (objectOutputStream != null) { objectOutputStream.flush(); objectOutputStream.close(); } } }