List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
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 w w w .j av a 2 s . co m }
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); oos.close();//from w ww . j a va2s . c o m 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:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException/* ww w . j a v a 2 s . c om*/ * @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:fr.hoteia.qalingo.core.dao.impl.EmailDaoImpl.java
/** * @throws IOException//from ww w.j a va2s . c o m * @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:it.unibo.alchemist.language.protelis.MethodCall.java
private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject();// w w w . ja v a2 s. co m out.writeObject(method.getDeclaringClass()); out.writeUTF(method.getName()); out.writeObject(method.getParameterTypes()); }
From source file:com.metamx.tranquility.javatests.StormJavaApiTest.java
@Test public void testDruidBeamBoltConstruction() throws Exception { final BeamBolt<Map<String, Object>> beamBolt = new BeamBolt<>(new MyBeamFactory()); // Ensure serializability final ObjectOutputStream objectOutputStream = new ObjectOutputStream(new ByteArrayOutputStream()); objectOutputStream.writeObject(beamBolt); Assert.assertTrue(true);//from w ww. j a va 2s.co m }
From source file:io.lqd.sdk.model.LQLiquidPackage.java
public void saveToDisk(Context context) { LQLog.data("Saving to local storage"); try {/*from ww w.j av a 2 s . c o m*/ 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:jade.content.onto.SerializableOntology.java
/** *//*from w ww .j a v a2 s.co m*/ protected AbsObject fromObject(Object obj, Ontology globalOnto) throws UnknownSchemaException, OntologyException { // If obj is already an abstract descriptor --> just return it if (obj instanceof AbsObject) { return (AbsObject) obj; } if (obj instanceof Serializable) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(obj); AbsConcept absSerializable = new AbsConcept(SERIALIZABLE); String stringValue = new String(Base64.encodeBase64(baos.toByteArray()), "US-ASCII"); absSerializable.set(SERIALIZABLE_VALUE, stringValue); return absSerializable; } catch (Throwable t) { throw new OntologyException("Error in object serialization.", t); } } else { throw new OntologyException("Object " + obj + " is not serializable"); } }
From source file:com.tempescope.wunderground.WeatherLocationManager.java
public void save() { if (file != null) { try {//w ww . ja va 2s . c om ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream(file))); out.writeObject(this); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.blanco.techmun.android.cproviders.MesasFetcher.java
private void saveOnCache(Context context, Mesas mesas) { try {//from w ww.j ava 2 s . c o m FileOutputStream mesasFOS = context.openFileOutput("mesas.df", Context.MODE_PRIVATE); ObjectOutputStream mesasOOS = new ObjectOutputStream(mesasFOS); mesasOOS.writeObject(mesas); mesasOOS.close(); PreferenceManager.getDefaultSharedPreferences(context).edit() .putLong("mesas_last_cache_saved", System.currentTimeMillis()).commit(); } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be saved", e); } }