List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java
/** * Set disk cache path to store downloaded rss images * @param cachePath - disk cache path// w w w.j a va2 s .c o m */ public void setCachePath(String cachePath) { this.cachePath = cachePath; try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cachePath + "/cache.data")); oos.writeObject(items); oos.flush(); oos.close(); } catch (Exception e) { } }
From source file:com.dev.pygmy.util.Utils.java
/** * Saves the current game by serializing it and storing in locally * on the device//w w w . ja v a2 s . c o m */ public static void saveGame(PygmyGame game, String path) { ObjectOutputStream oos = null; try { File history = new File(path); history.getParentFile().createNewFile(); FileOutputStream fout = new FileOutputStream(history); oos = new ObjectOutputStream(fout); oos.writeObject(game); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (oos != null) { oos.flush(); oos.close(); } } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:com.kyne.webby.bukkit.RTKModuleSocket.java
@Override public void run() { LogHelper.info("Webby Socket (BukkitPlugin) is listening on port : " + this.serverSocket.getLocalPort()); while (!this.serverSocket.isClosed()) { // this.requestCount++; Socket clientSocket = null; ObjectInputStream ois = null; ObjectOutputStream oos = null; try {//www .j ava 2s. com clientSocket = this.serverSocket.accept(); ois = new ObjectInputStream(clientSocket.getInputStream()); oos = new ObjectOutputStream(clientSocket.getOutputStream()); final WebbyLocalData request = (WebbyLocalData) ois.readObject(); final WebbyLocalData response = this.handleRequest(request); oos.writeObject(response); } catch (final SocketException e) { LogHelper.warn("Socket has been closed. If bukkit is stopping or restarting, this is normal"); } catch (final IOException e) { LogHelper.error("An error occured while waiting for connections", e); } catch (final ClassNotFoundException e) { LogHelper.error("Unsupported object was sent to Webby ", e); } finally { IOUtils.closeQuietly(ois); IOUtils.closeQuietly(oos); IOUtils.closeQuietly(clientSocket); } } }
From source file:com.machinepublishers.jbrowserdriver.HttpCache.java
/** * {@inheritDoc}/*w ww. ja v a 2 s . co m*/ */ @Override public void putEntry(String key, HttpCacheEntry entry) throws IOException { try (Lock lock = new Lock(new File(cacheDir, DigestUtils.sha1Hex(key)), false, true)) { BufferedOutputStream bufferOut = new BufferedOutputStream(lock.streamOut); try (ObjectOutputStream objectOut = new ObjectOutputStream(bufferOut)) { objectOut.writeObject(entry); } } }
From source file:de.fu_berlin.inf.dpp.videosharing.net.ConnectionFactory.java
/** * /* w w w . j a v a2s . c om*/ * @param session * @param mode * @throws IOException */ public ConnectionFactory(StreamSession session, Mode mode) throws IOException { this.mode = mode; this.session = session; try { switch (mode) { case CLIENT: clientVideoIn = session.getInputStream(0); clientStatisticsOut = new ObjectOutputStream(session.getOutputStream(0)); clientStatisticsOut.flush(); clientActivitiesOut = new ObjectOutputStream(session.getOutputStream(1)); clientActivitiesOut.flush(); clientErrorIn = new ObjectInputStream(session.getInputStream(1)); break; case HOST: hostVideoOut = session.getOutputStream(0); hostStatisticsIn = new ObjectInputStream(session.getInputStream(0)); hostActivitiesIn = new ObjectInputStream(session.getInputStream(1)); hostErrorOut = new ObjectOutputStream(session.getOutputStream(1)); hostErrorOut.flush(); break; default: break; } } catch (IOException e) { session.dispose(); throw e; } }
From source file:de.scoopgmbh.copper.persistent.StandardJavaSerializer.java
private String serialize(final Object o) throws IOException { if (o == null) return null; final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);//www . j a v a 2 s . c om oos.close(); baos.close(); byte[] data = baos.toByteArray(); boolean isCompressed = false; if (compress && compressThresholdSize <= data.length && data.length <= compressorMaxSize) { data = compressorTL.get().compress(data); isCompressed = true; } final String encoded = new Base64().encodeToString(data); final StringBuilder sb = new StringBuilder(encoded.length() + 4); sb.append(isCompressed ? 'C' : 'U').append(encoded); return sb.toString(); }
From source file:com.twosigma.beaker.cpp.utils.CppKernel.java
public int execute(String mainCell, String type, ArrayList<String> otherCells) { String tmpDir = System.getenv("beaker_tmp_dir"); for (String cell : otherCells) { cLoad(tmpDir + "/lib" + cell + ".so"); }/*from w ww. j a v a 2 s . c o m*/ Object ret = cLoadAndRun(tmpDir + "/lib" + mainCell + ".so", type); try { FileOutputStream file = new FileOutputStream(tmpDir + "/" + mainCell + ".result"); BufferedOutputStream buffer = new BufferedOutputStream(file); ObjectOutputStream output = new ObjectOutputStream(buffer); output.writeObject(ret); output.close(); } catch (IOException ex) { logger.warn("Could not load file"); return 1; } return 0; }
From source file:aajavafx.LoginController.java
@FXML private void handleButtonLoginAction(ActionEvent event) { try {//from w w w.j av a 2s .c o m username_var = userID.getText().toString(); password_var = passwordID.getText().toString(); Kripto myKripto = new Kripto(); System.out.println(myKripto.encrypt(password_var)); if (saveCredentials.isSelected()) { UserCredentials userCred = new UserCredentials(username_var, password_var); try (ObjectOutputStream out = new ObjectOutputStream(Files.newOutputStream(savedCredentials))) { out.writeObject(userCred); } catch (IOException ex) { System.out.println("IO Exception: " + ex); } catch (Exception ex) { System.out.println("Exception: " + ex); ; } } //////Check password disabled // String passwordCypherFromDB = getPassword(username_var); // String passwordFromDB = myKripto.decrypt(passwordCypherFromDB); // if (passwordFromDB.equals(password_var)) { Node node = (Node) event.getSource(); Stage stage = (Stage) node.getScene().getWindow(); FXMLLoader loader = new FXMLLoader(getClass().getResource("MainPageTab.fxml")); Parent root = loader.load(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); System.out.println("Taking you to next page!"); // } else { // outputmessageID.setText("Login failed!!!!"); // } } catch (Exception ex) { System.out.println("LOAD PAGE EXCEPTION: " + ex); } System.out.println("You clicked me!"); }
From source file:com.qwazr.utils.server.InFileSessionPersistenceManager.java
private void writeSession(File deploymentDir, String sessionId, PersistentSession persistentSession) { final Date expDate = persistentSession.getExpiration(); if (expDate == null) return; // No expiry date? no serialization final Map<String, Object> sessionData = persistentSession.getSessionData(); if (sessionData == null || sessionData.isEmpty()) return; // No attribute? no serialization File sessionFile = new File(deploymentDir, sessionId); try {/* w w w .j a v a 2 s . co m*/ final FileOutputStream fileOutputStream = new FileOutputStream(sessionFile); try { final ObjectOutputStream out = new ObjectOutputStream(fileOutputStream); try { out.writeLong(expDate.getTime()); // The date is stored as long sessionData.forEach((attribute, object) -> writeSessionAttribute(out, attribute, object)); } finally { IOUtils.close(out); } } finally { IOUtils.close(fileOutputStream); } } catch (IOException e) { if (logger.isWarnEnabled()) logger.warn("Cannot save sessions in " + sessionFile + " " + e.getMessage(), e); } }
From source file:org.appverse.web.framework.backend.core.enterprise.aop.managers.impl.live.ProfileManagerImpl.java
private String getObjectSize(Object object) throws IOException { if (object instanceof Serializable) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos); out.writeObject(object);//from www.ja v a 2s . com out.close(); byte[] buf = bos.toByteArray(); return String.valueOf(buf.length); } return "Unknow"; }