/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream @out) { @out.WriteObject(cookie.GetName()); @out.WriteObject(cookie.GetValue()); @out.WriteObject(cookie.GetComment()); @out.WriteObject(cookie.GetDomain()); @out.WriteObject(cookie.GetExpiryDate()); @out.WriteObject(cookie.GetPath()); @out.WriteInt(cookie.GetVersion()); @out.WriteBoolean(cookie.IsSecure()); }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream os) { os.WriteInt(w1); os.WriteInt(w2); os.WriteInt(w3); os.WriteInt(w4); os.WriteInt(w5); }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream os) { os.DefaultWriteObject(); int N = size; for (int i = 0; i != N; ++i) { object obj = GetImpl(i); os.WriteObject(obj); } }
// end encodeObject /// <summary> /// Serializes an object and returns the Base64-encoded /// version of that serialized object. /// </summary> /// <remarks> /// Serializes an object and returns the Base64-encoded /// version of that serialized object. /// <p>As of v 2.3, if the object /// cannot be serialized or there is another error, /// the method will throw an java.io.IOException. <b>This is new to v2.3!</b> /// In earlier versions, it just returned a null value, but /// in retrospect that's a pretty poor way to handle it.</p> /// The object is not GZip-compressed before being encoded. /// <p> /// Example options:<pre> /// GZIP: gzip-compresses object before encoding it. /// DO_BREAK_LINES: break lines at 76 characters /// </pre> /// <p> /// Example: <code>encodeObject( myObj, Base64.GZIP )</code> or /// <p> /// Example: <code>encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES )</code> /// </remarks> /// <param name="serializableObject">The object to encode</param> /// <param name="options">Specified options</param> /// <returns>The Base64-encoded object</returns> /// <seealso cref="Gzip">Gzip</seealso> /// <seealso cref="DoBreakLines">DoBreakLines</seealso> /// <exception cref="System.IO.IOException">if there is an error</exception> /// <since>2.0</since> public static string EncodeObject(Serializable serializableObject, int options) { if (serializableObject == null) { throw new ArgumentNullException("Cannot serialize a null object."); } // end if: null // Streams ByteArrayOutputStream baos = null; OutputStream b64os = null; GZIPOutputStream gzos = null; ObjectOutputStream oos = null; try { // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream baos = new ByteArrayOutputStream(); b64os = new Base64.OutputStream(baos, Encode | options); if ((options & Gzip) != 0) { // Gzip gzos = new GZIPOutputStream(b64os); oos = new ObjectOutputStream(gzos); } else { // Not gzipped oos = new ObjectOutputStream(b64os); } oos.WriteObject(serializableObject); } catch (IOException e) { // end try // Catch it and then throw it immediately so that // the finally{} block is called for cleanup. throw; } finally { // end catch try { oos.Close(); } catch (Exception) { } try { gzos.Close(); } catch (Exception) { } try { b64os.Close(); } catch (Exception) { } try { baos.Close(); } catch (Exception) { } } // end finally // Return value according to relevant encoding. try { return Sharpen.Runtime.GetStringForBytes(baos.ToByteArray(), PreferredEncoding); } catch (UnsupportedEncodingException) { // end try // Fall back to some Java default return Sharpen.Runtime.GetStringForBytes(baos.ToByteArray()); } }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream stream) { stream.DefaultWriteObject(); int maxPrototypeId = 0; if (prototypeValues != null) { maxPrototypeId = prototypeValues.GetMaxId(); } stream.WriteInt(maxPrototypeId); }
public virtual void TestConsStringSerialization() { ConsString r1 = new ConsString("foo", "bar"); MemoryStream baos = new MemoryStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.WriteObject(r1); oos.Flush(); MemoryStream bais = new MemoryStream(baos.ToArray()); ObjectInputStream ois = new ObjectInputStream(bais); CharSequence r2 = (CharSequence)ois.ReadObject(); NUnit.Framework.Assert.AreEqual("still the same at the other end", r1.ToString(), r2.ToString()); }
public virtual void TestContinuationsPrototypesAndSerialization() { byte[] serializedData = null; { Scriptable globalScope; Context cx = Context.Enter(); try { globalScope = cx.InitStandardObjects(); cx.SetOptimizationLevel(-1); // must use interpreter mode globalScope.Put("myObject", globalScope, Context.JavaToJS(new ContinuationsApiTest.MyClass(), globalScope)); } finally { Context.Exit(); } cx = Context.Enter(); try { cx.SetOptimizationLevel(-1); // must use interpreter mode cx.EvaluateString(globalScope, "function f(a) { Number.prototype.blargh = function() {return 'foo';}; var k = myObject.f(a); var t = []; return new Number(8).blargh(); }", "function test source", 1, null); Function f = (Function)globalScope.Get("f", globalScope); object[] args = new object[] { 7 }; cx.CallFunctionWithContinuations(f, globalScope, args); NUnit.Framework.Assert.Fail("Should throw ContinuationPending"); } catch (ContinuationPending pending) { // serialize MemoryStream baos = new MemoryStream(); ObjectOutputStream sos = new ObjectOutputStream(baos); sos.WriteObject(globalScope); sos.WriteObject(pending.GetContinuation()); sos.Close(); baos.Close(); serializedData = baos.ToArray(); } finally { Context.Exit(); } } { try { Context cx = Context.Enter(); Scriptable globalScope; // deserialize MemoryStream bais = new MemoryStream(serializedData); ObjectInputStream sis = new ObjectInputStream(bais); globalScope = (Scriptable)sis.ReadObject(); object continuation = sis.ReadObject(); sis.Close(); bais.Close(); object result = cx.ResumeContinuation(continuation, globalScope, 8); NUnit.Framework.Assert.AreEqual("foo", result); } finally { Context.Exit(); } } }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream @out) { @out.DefaultWriteObject(); int count = keyCount; for (int i = 0; count != 0; ++i) { object key = keys[i]; if (key != null && key != DELETED) { --count; @out.WriteObject(key); @out.WriteInt(values[i]); } } }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream @out) { @out.DefaultWriteObject(); int count = keyCount; if (count != 0) { bool hasIntValues = (ivaluesShift != 0); bool hasObjectValues = (values != null); @out.WriteBoolean(hasIntValues); @out.WriteBoolean(hasObjectValues); for (int i = 0; count != 0; ++i) { int key = keys[i]; if (key != EMPTY && key != DELETED) { --count; @out.WriteInt(key); if (hasIntValues) { @out.WriteInt(keys[ivaluesShift + i]); } if (hasObjectValues) { @out.WriteObject(values[i]); } } } } }