List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:SaveYourDrawingToFile.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { displayList = new Vector(); repaint();/*from ww w . java 2s . co m*/ } else if (e.getSource() == saveBtn) { try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (Exception ex) { System.out.println("Trouble writing display list vector"); } } else if (e.getSource() == restoreBtn) { try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (Vector) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (Exception ex) { System.out.println("Trouble reading display list vector"); } } else if (e.getSource() == quitBtn) { setVisible(false); dispose(); System.exit(0); } }
From source file:org.craftercms.security.utils.crypto.KeyFile.java
/** * Writes the given key to the files through an {@link ObjectOutputStream}. *//* w w w. j a va 2 s . c o m*/ public void writeKey(Key key) throws IOException { ObjectOutputStream out = new ObjectOutputStream(FileUtils.openOutputStream(file)); try { out.writeObject(key); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:org.eclipse.ecr.core.storage.sql.net.ObjectWriterRequestEntity.java
@Override public void writeRequest(OutputStream out) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(out); for (Object object : queue) { oos.writeObject(object);//from w w w . j a va2s .c o m } oos.flush(); }
From source file:PersisTest.java
public void actionPerformed(ActionEvent e) { if (e.getSource() == clearBtn) { // Repaint with an empty display list. displayList = new ArrayList(); repaint();//from ww w . j a v a 2s .c om } else if (e.getSource() == saveBtn) { // Write display list array list to an object output stream. try { FileOutputStream fos = new FileOutputStream(pathname); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(displayList); oos.flush(); oos.close(); fos.close(); } catch (IOException ex) { System.err.println("Trouble writing display list array list"); } } else if (e.getSource() == restoreBtn) { // Read a new display list array list from an object input stream. try { FileInputStream fis = new FileInputStream(pathname); ObjectInputStream ois = new ObjectInputStream(fis); displayList = (ArrayList) (ois.readObject()); ois.close(); fis.close(); repaint(); } catch (ClassNotFoundException ex) { System.err.println("Trouble reading display list array list"); } catch (IOException ex) { System.err.println("Trouble reading display list array list"); } } else if (e.getSource() == quitBtn) { System.exit(0); } }
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetTicketsMethod.java
/** * Execute the JSONRPCFunction.//from ww w .j av a 2s. c o m * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); JSONArray tickets = new JSONArray(); String ticketId = null; if (params.length() != 0) { throw new JSONRPCException(-32602, "Invalid Params"); } for (Ticket ticket : this.map.values()) { byte[] serializedTicketArray = { 0 }; try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicketArray = bo.toByteArray(); } catch (final Exception e) { logger.debug(e.getMessage()); throw new JSONRPCException(-32500, "Error extracting Ticket"); } tickets.put(DatatypeConverter.printBase64Binary(serializedTicketArray)); } logger.debug("GetTickets: " + tickets.length()); result.put("tickets", tickets); return result; }
From source file:org.nuxeo.ecm.core.redis.contribs.RedisCache.java
protected byte[] serializeValue(Serializable value) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baout); out.writeObject(value);// ww w .j a va 2s .c o m out.flush(); out.close(); return baout.toByteArray(); }
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetMethod.java
/** * Execute the JSONRPCFunction.//from w w w .j a v a 2 s. c om * * @param params JSONRPC Method Parameters. * * @return JSONRPC result object * * @throws JSONRPCException implementors can throw JSONRPCExceptions containing the error. */ public JSONObject execute(final JSONObject params) throws JSONRPCException { JSONObject result = new JSONObject(); Ticket ticket; logger.debug("GET"); String ticketId = null; if (params.length() != 1) { throw new JSONRPCException(-32602, "Invalid Params"); } if (!(params.has("ticket-id"))) { throw new JSONRPCException(-32602, "Invalid Params"); } ticketId = params.getString("ticket-id"); ticket = this.map.get(ticketId.hashCode()); if (ticket == null) { throw new JSONRPCException(-32503, "Missing Ticket"); } byte[] serializedTicketArray = { 0 }; try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicketArray = bo.toByteArray(); } catch (final Exception e) { logger.debug(e.getMessage()); throw new JSONRPCException(-32500, "Error extracting Ticket"); } result.put("ticket-id", ticketId); result.put("ticket", DatatypeConverter.printBase64Binary(serializedTicketArray)); return result; }
From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java
protected void setParameterInternal(PreparedStatement ps, int index, Object value, String jdbcType, LobCreator lobCreator) throws SQLException, IOException { if (value != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); try {/* w w w . j a va2 s . c om*/ oos.writeObject(value); oos.flush(); lobCreator.setBlobAsBytes(ps, index, baos.toByteArray()); } finally { oos.close(); } } else { lobCreator.setBlobAsBytes(ps, index, null); } }
From source file:org.apache.axis2.clustering.tribes.ChannelSender.java
private ByteMessage toByteMessage(ClusteringCommand msg) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(msg);//from w ww . j av a2s.c o m out.flush(); out.close(); return new ByteMessage(bos.toByteArray()); }
From source file:org.compass.gps.device.hibernate.scrollable.snapshot.FSHibernateSnapshotPersister.java
public void save(HibernateSnapshot snapshot) throws HibernateGpsDeviceException { try {/*from ww w . j av a 2s.c om*/ 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 HibernateGpsDeviceException("Failed to save hibernate snapshot", e); } }