List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:com.ps.cc.controller.Init.java
@ActionMapping(params = "action=saveTwilioConfiguration") public void saveTwilioConfiguration(@ModelAttribute TwilioConfiguration twilioConfiguration, ActionRequest actionRequest) throws Exception { ObjectOutput out = new ObjectOutputStream(new FileOutputStream("twilioConfiguration.txt")); out.writeObject(twilioConfiguration); out.close();/*from w ww . j a va2 s . c om*/ User user = PortalUtil.getUser(actionRequest); TwilioCapability capability = new TwilioCapability(twilioConfiguration.getAcctSid(), twilioConfiguration.getAuthToken()); capability.allowEventStream(null); capability.allowClientIncoming(user.getScreenName()); Map<String, String> params = new HashMap<String, String>(); params.put("portraitId", String.valueOf(user.getPortraitId())); capability.allowClientOutgoing(twilioConfiguration.getAppSid(), params); String token = capability.generateToken(); PortalUtil.getHttpServletRequest(actionRequest).getSession().setAttribute("USER_twilio_token", token); }
From source file:com.limegroup.gnutella.licenses.WeedLicenseTest.java
public void testSerializeAndDeserialize() throws Exception { License l = new StubWeedLicense("3", "4", "page"); assertEquals(null, l.getLicense());//from ww w . j a va2s . co m assertEquals("http://weedshare.com/company/policies/summary_usage_rights.aspx", l.getLicenseDeed(null).toString()); assertEquals("http://www.weedshare.com/license/verify_usage_rights.aspx?versionid=4&contentid=3", l.getLicenseURI().toString()); assertEquals("Details unknown.", l.getLicenseDescription(null)); assertFalse(l.isVerified()); assertFalse(l.isValid(null)); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(l); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); l = (License) in.readObject(); assertEquals(null, l.getLicense()); // CHANGE -- not serialized (but unused anyway) assertEquals("http://weedshare.com/company/policies/summary_usage_rights.aspx", l.getLicenseDeed(null).toString()); assertEquals(null, l.getLicenseURI()); // CHANGE -- not serialized assertEquals("Details unknown.", l.getLicenseDescription(null)); assertTrue(l.isVerified()); // CHANGE -- becomes verified assertFalse(l.isValid(null)); // Now try with a full out parsed License. l = new StubWeedLicense("3", "4", xml(true, "Sammy B", "Blues In G", "$4.20")); l.verify(null); assertEquals(null, l.getLicense()); assertTrue(l.isVerified()); assertTrue(l.isValid(null)); assertEquals("http://weedshare.com/company/policies/summary_usage_rights.aspx", l.getLicenseDeed(null).toString()); assertEquals("Artist: Sammy B\nTitle: Blues In G\nPrice: $4.20", l.getLicenseDescription(null)); bout = new ByteArrayOutputStream(); out = new ObjectOutputStream(bout); out.writeObject(l); bin = new ByteArrayInputStream(bout.toByteArray()); in = new ObjectInputStream(bin); l = (License) in.readObject(); assertEquals(null, l.getLicense()); // CHANGE -- not serialized (but unused) assertTrue(l.isVerified()); assertTrue(l.isValid(null)); assertEquals("http://weedshare.com/company/policies/summary_usage_rights.aspx", l.getLicenseDeed(null).toString()); assertEquals("Artist: Sammy B\nTitle: Blues In G\nPrice: $4.20", l.getLicenseDescription(null)); }
From source file:com.jpeterson.littles3.bo.BucketTest.java
/** * Test that an instance is serializable. *//*from w w w.jav a2 s . com*/ public void test_serialization() { Bucket bucket, reconstitutedBucket; ByteArrayInputStream bais; ByteArrayOutputStream baos; ObjectInputStream ois; ObjectOutputStream oos; Date now = new Date(); bucket = new Bucket(); bucket.setName("test"); bucket.setCreated(now); try { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(bucket); bais = new ByteArrayInputStream(baos.toByteArray()); ois = new ObjectInputStream(bais); reconstitutedBucket = (Bucket) ois.readObject(); assertEquals("Unexpected value", "test", reconstitutedBucket.getName()); assertEquals("Unexpected value", now, reconstitutedBucket.getCreated()); } catch (IOException e) { e.printStackTrace(); fail("Unexpected exception"); } catch (ClassNotFoundException e) { e.printStackTrace(); fail("Unexpected exception"); } }
From source file:com.mobicage.rogerthat.mfr.dal.Streamable.java
public String toBase64() { try {//from w w w. j av a 2 s . c om ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ZipOutputStream zip = new ZipOutputStream(bos); try { zip.setLevel(9); zip.putNextEntry(new ZipEntry("entry")); try { ObjectOutput out = new ObjectOutputStream(zip); try { out.writeObject(this); } finally { out.flush(); } } finally { zip.closeEntry(); } zip.flush(); return Base64.encodeBase64URLSafeString(bos.toByteArray()); } finally { zip.close(); } } finally { bos.close(); } } catch (IOException e) { log.log((Level.SEVERE), "IO Error while serializing member", e); return null; } }
From source file:com.github.stephanarts.cas.ticket.registry.provider.GetMethod.java
/** * Execute the JSONRPCFunction.// w w w .java 2s . co 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(); 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:com.marintek.isis.wicket.popupbox.applib.PopupWicketBoxSemanticsProvider.java
static String toString(Serializable serializable) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try {/*from w ww . j a v a 2 s . co m*/ oos = new ObjectOutputStream(baos); oos.writeObject(serializable); return new String(Base64.encodeBase64(baos.toByteArray())); } catch (IOException e) { throw new Base64Serializer.Exception(e); } finally { try { if (oos != null) { oos.close(); } } catch (IOException e) { throw new Base64Serializer.Exception(e); } } }
From source file:org.blanco.techmun.android.cproviders.EventosFetcher.java
private void saveOnCache(Context context, Eventos eventos, long mesaId) { try {/*from ww w .j a v a 2 s . c om*/ FileOutputStream mesasFOS = context.openFileOutput("eventos_" + mesaId + ".df", Context.MODE_PRIVATE); ObjectOutputStream mesasOOS = new ObjectOutputStream(mesasFOS); mesasOOS.writeObject(eventos); mesasOOS.close(); PreferenceManager.getDefaultSharedPreferences(context).edit() .putLong("eventos_last_refresh", System.currentTimeMillis()).commit(); //We just cached the events set the preference to not force the refresh again until expiration time PreferenceManager.getDefaultSharedPreferences(context).edit() .putBoolean("force_eventos_refresh_" + mesaId, false).commit(); } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be saved", e); } }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void sizeExternalizeSeveralWithType(String type, Externalizable[] objects) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/* w ww .j a v a 2 s . c om*/ ObjectOutputStream out = new ObjectOutputStream(baos); for (Externalizable object : objects) { Message msg = new MessageImpl(type, object, null); out.writeObject(msg); } out.close(); } catch (IOException ex) { ex.printStackTrace(); } int size = baos.size(); int sizePerMessage = size / objects.length; System.out.println(" Size indicating types " + objects.length + " messages - RMI: " + size + " bytes (" + sizePerMessage + " bytes/msg)"); }
From source file:jp.queuelinker.system.util.SerializeUtil.java
/** * @param obj/* w w w . ja v a2 s . c om*/ * @param file * @throws IOException */ public static void storeObject(final Object obj, final File file) throws IOException { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(file)); output.writeObject(obj); }
From source file:net.brtly.monkeyboard.api.plugin.Bundle.java
/** * Convert a Bundle object to a byte array that can be deserialized by * {@link #fromByteArray(byte[])}/*from ww w . j ava 2 s . c om*/ * * @param b * @return * @throws IOException */ public static byte[] toByteArray(Bundle b) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(b); return bos.toByteArray(); } finally { out.close(); bos.close(); } }