List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:net.sf.dynamicreports.googlecharts.test.AbstractJasperTest.java
private JasperReportBuilder serializableTest(JasperReportBuilder report) throws IOException, ClassNotFoundException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(report);/*from w ww . j a v a2 s . c om*/ oos.flush(); oos.close(); InputStream stream = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(stream); return (JasperReportBuilder) ois.readObject(); }
From source file:edu.stanford.muse.lens.LensPrefs.java
private void savePrefs() { try {//w w w . j a v a 2 s. c om FileOutputStream fos = new FileOutputStream(pathToPrefsFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(prefs); oos.flush(); oos.close(); PrintStream ps = new PrintStream(new FileOutputStream(pathToPrefsFile + ".txt")); for (String term : prefs.keySet()) { Map<String, Float> map = prefs.get(term); for (String url : map.keySet()) ps.println(term + "\t" + url + "\t" + map.get(url)); } ps.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.spout.api.datatable.SerializableData.java
@Override public byte[] compress() { Serializable value = super.get(); if (value instanceof ByteArrayWrapper) { return ((ByteArrayWrapper) value).getArray(); }//from w ww.j av a2 s. c o m ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try { ObjectOutputStream objOut = new ObjectOutputStream(byteOut); objOut.writeObject(super.get()); objOut.flush(); objOut.close(); } catch (IOException e) { if (Spout.debugMode()) { Spout.getLogger().log(Level.SEVERE, "Unable to serialize " + value + " (type: " + (value != null ? value.getClass().getSimpleName() : "null") + ")", e); } return null; } return byteOut.toByteArray(); }
From source file:com.github.stephanarts.cas.ticket.registry.provider.UpdateMethodTest.java
@Test public void testValidInput() throws Exception { final byte[] serializedTicket; final HashMap<Integer, Ticket> map = new HashMap<Integer, Ticket>(); final JSONObject params = new JSONObject(); final IMethod method = new UpdateMethod(map); final String ticketId = "ST-1234567890ABCDEFGHIJKL-crud"; final ServiceTicket ticket = mock(ServiceTicket.class, withSettings().serializable()); when(ticket.getId()).thenReturn(ticketId); map.put(ticketId.hashCode(), ticket); try {//from w w w. j av a 2s . co m ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(ticket); so.flush(); serializedTicket = bo.toByteArray(); params.put("ticket-id", ticketId); params.put("ticket", DatatypeConverter.printBase64Binary(serializedTicket)); method.execute(params); } catch (final JSONRPCException e) { Assert.fail(e.getMessage()); } catch (final Exception e) { throw new Exception(e); } }
From source file:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException//from www.j av a2s.c om * @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:org.apache.geronimo.crypto.ConfiguredEncryption.java
public ConfiguredEncryption(String location) throws IOException { File keyFile = new File(location); ObjectInputStream oin = null; if (keyFile != null) { if (keyFile.exists()) { FileInputStream fi = new FileInputStream(keyFile); try { oin = new ObjectInputStream(fi); spec = (SecretKeySpec) oin.readObject(); } catch (ClassNotFoundException e) { log.error("Unable to read object or class not found: ", e); } finally { if (oin != null) oin.close();//w w w .ja v a 2 s .c o m if (fi != null) fi.close(); } } else { SecureRandom random = new SecureRandom(); random.setSeed(System.currentTimeMillis()); byte[] bytes = new byte[16]; random.nextBytes(bytes); spec = new SecretKeySpec(bytes, "AES"); File dir = keyFile.getParentFile(); if (!dir.exists()) { dir.mkdirs(); } if (!dir.exists() || !dir.isDirectory()) { throw new IllegalStateException("Could not create directory for secret key spec: " + dir); } FileOutputStream out = new FileOutputStream(keyFile); try { ObjectOutputStream oout = new ObjectOutputStream(out); try { oout.writeObject(spec); oout.flush(); } finally { oout.close(); } } finally { out.close(); } log.info("Generate a new configured encryption password: " + spec.getEncoded().toString()); } } }
From source file:gov.nih.nci.caarray.util.CaArrayUtilsTest.java
@Test public void testSerializeDeserialize2() throws IOException, ClassNotFoundException { QuantitationType qt = new QuantitationType(); qt.setDataType(DataType.FLOAT);/* w w w . jav a 2s . co m*/ qt.setName("Foo"); FloatColumn fc = new FloatColumn(); fc.setQuantitationType(qt); fc.setValues(TEST_FLOAT_ARRAY); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(fc); oos.flush(); byte[] serialized = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(serialized); ObjectInputStream ois = new ObjectInputStream(bais); FloatColumn in = (FloatColumn) ois.readObject(); assertEquals(qt, in.getQuantitationType()); float[] deserialized = in.getValues(); assertEquals(TEST_FLOAT_ARRAY.length, deserialized.length); for (int i = 0; i < TEST_FLOAT_ARRAY.length; i++) { assertEquals(TEST_FLOAT_ARRAY[i], deserialized[i], 0); } }
From source file:io.lqd.sdk.model.LQLiquidPackage.java
public void saveToDisk(Context context) { LQLog.data("Saving to local storage"); try {//w w w . jav a2s.com FileOutputStream fileOutputStream = context.openFileOutput(LIQUID_PACKAGE_FILENAME + ".vars", Context.MODE_PRIVATE); ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(this); objectOutputStream.flush(); objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); LQLog.infoVerbose("Could not save liquid package to file"); } }
From source file:org.n52.geoar.newdata.PluginLoader.java
/** * Saves the state of plugins to {@link SharedPreferences}. *///from w w w . j av a 2s. c om public static void saveState() { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); // store plugin state version objectOutputStream.writeInt(PLUGIN_STATE_VERSION); List<InstalledPluginHolder> checkedPlugins = mInstalledPlugins.getCheckedItems(); objectOutputStream.writeInt(checkedPlugins.size()); for (InstalledPluginHolder plugin : checkedPlugins) { objectOutputStream.writeUTF(plugin.getIdentifier()); plugin.saveState(objectOutputStream); } SharedPreferences preferences = GeoARApplication.applicationContext .getSharedPreferences(GeoARApplication.PREFERENCES_FILE, Context.MODE_PRIVATE); Editor editor = preferences.edit(); objectOutputStream.flush(); editor.putString(PLUGIN_STATE_PREF, Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)); editor.commit(); objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); // TODO } }
From source file:hydrograph.ui.graph.handler.JobCreationPage.java
protected InputStream getInitialContents() { ByteArrayInputStream bais = null; try {//ww w.j a v a2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.flush(); oos.close(); bais = new ByteArrayInputStream(baos.toByteArray()); } catch (IOException e) { logger.error("Error while job wizard creation", e); } return bais; }