public virtual void TestSerializePolyline()
 {
     try
     {
         java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream    oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.Polyline     pt        = new com.epl.geometry.Polyline();
         pt.StartPath(10, 10);
         pt.LineTo(100, 100);
         pt.LineTo(200, 100);
         oo.WriteObject(pt);
         System.IO.BinaryWriter    streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.Polyline ptRes    = (com.epl.geometry.Polyline)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception)
     {
         Fail("Polyline serialization failure");
     }
     //try
     //{
     //FileOutputStream streamOut = new FileOutputStream("c:/temp/savedPolyline1.txt");
     //ObjectOutputStream oo = new ObjectOutputStream(streamOut);
     //Polyline pt = new Polyline();
     //pt.startPath(10, 10);
     //pt.lineTo(100, 100);
     //pt.lineTo(200, 100);
     //oo.writeObject(pt);
     //}
     //catch(Exception ex)
     //{
     //fail("Polyline serialization failure");
     //}
     try
     {
         java.io.InputStream       s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedPolyline.txt");
         java.io.ObjectInputStream ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.Polyline ptRes = (com.epl.geometry.Polyline)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes != null);
     }
     catch (System.Exception)
     {
         Fail("Polyline serialization failure");
     }
     try
     {
         java.io.InputStream       s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedPolyline1.txt");
         java.io.ObjectInputStream ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.Polyline ptRes = (com.epl.geometry.Polyline)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes != null);
     }
     catch (System.Exception)
     {
         Fail("Polyline serialization failure");
     }
 }
 public virtual void TestSerializeMultiPoint()
 {
     try
     {
         java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream    oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.MultiPoint   pt        = new com.epl.geometry.MultiPoint();
         pt.Add(10, 30);
         pt.Add(120, 40);
         oo.WriteObject(pt);
         System.IO.BinaryWriter      streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream   ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.MultiPoint ptRes    = (com.epl.geometry.MultiPoint)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception)
     {
         Fail("MultiPoint serialization failure");
     }
     //try
     //{
     //FileOutputStream streamOut = new FileOutputStream("c:/temp/savedMultiPoint1.txt");
     //ObjectOutputStream oo = new ObjectOutputStream(streamOut);
     //MultiPoint pt = new MultiPoint();
     //pt.add(10, 30);
     //pt.add(120, 40);
     //oo.writeObject(pt);
     //}
     //catch(Exception ex)
     //{
     //fail("MultiPoint serialization failure");
     //}
     try
     {
         java.io.InputStream         s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedMultiPoint.txt");
         java.io.ObjectInputStream   ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.MultiPoint ptRes = (com.epl.geometry.MultiPoint)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.GetPoint(1).GetY() == 40);
     }
     catch (System.Exception)
     {
         Fail("MultiPoint serialization failure");
     }
     try
     {
         java.io.InputStream         s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedMultiPoint1.txt");
         java.io.ObjectInputStream   ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.MultiPoint ptRes = (com.epl.geometry.MultiPoint)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.GetPoint(1).GetY() == 40);
     }
     catch (System.Exception)
     {
         Fail("MultiPoint serialization failure");
     }
 }
 public virtual void TestSerializeEnvelope()
 {
     try
     {
         java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream    oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.Envelope     pt        = new com.epl.geometry.Envelope(10, 10, 400, 300);
         oo.WriteObject(pt);
         System.IO.BinaryWriter    streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.Envelope ptRes    = (com.epl.geometry.Envelope)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception)
     {
         Fail("Envelope serialization failure");
     }
     //try
     //{
     //FileOutputStream streamOut = new FileOutputStream("c:/temp/savedEnvelope1.txt");
     //ObjectOutputStream oo = new ObjectOutputStream(streamOut);
     //Envelope pt = new Envelope(10, 10, 400, 300);
     //oo.writeObject(pt);
     //}
     //catch(Exception ex)
     //{
     //fail("Envelope serialization failure");
     //}
     try
     {
         java.io.InputStream       s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedEnvelope.txt");
         java.io.ObjectInputStream ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.Envelope ptRes = (com.epl.geometry.Envelope)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.GetXMax() == 400);
     }
     catch (System.Exception)
     {
         Fail("Envelope serialization failure");
     }
     try
     {
         java.io.InputStream       s     = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedEnvelope1.txt");
         java.io.ObjectInputStream ii    = new java.io.ObjectInputStream(s);
         com.epl.geometry.Envelope ptRes = (com.epl.geometry.Envelope)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.GetXMax() == 400);
     }
     catch (System.Exception)
     {
         Fail("Envelope serialization failure");
     }
 }
Exemple #4
0
        /// <summary>
        /// <code>readObject</code> for custom serialization.
        ///
        /// <para>This method reads this object's serialized form for this class
        /// as follows:
        ///
        /// </para>
        /// <para>The <code>readUTF</code> method is invoked on <code>in</code>
        /// to read the external ref type name for the <code>RemoteRef</code>
        /// instance to be filled in to this object's <code>ref</code> field.
        /// If the string returned by <code>readUTF</code> has length zero,
        /// the <code>readObject</code> method is invoked on <code>in</code>,
        /// and than the value returned by <code>readObject</code> is cast to
        /// <code>RemoteRef</code> and this object's <code>ref</code> field is
        /// set to that value.
        /// Otherwise, this object's <code>ref</code> field is set to a
        /// <code>RemoteRef</code> instance that is created of an
        /// implementation-specific class corresponding to the external ref
        /// type name returned by <code>readUTF</code>, and then
        /// the <code>readExternal</code> method is invoked on
        /// this object's <code>ref</code> field.
        ///
        /// </para>
        /// <para>If the external ref type name is
        /// <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>,
        /// <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>,
        /// or <code>"ActivatableRef"</code>, a corresponding
        /// implementation-specific class must be found, and its
        /// <code>readExternal</code> method must read the serial data
        /// for that external ref type name as specified to be written
        /// in the <b>serialData</b> documentation for this class.
        /// If the external ref type name is any other string (of non-zero
        /// length), a <code>ClassNotFoundException</code> will be thrown,
        /// unless the implementation provides an implementation-specific
        /// class corresponding to that external ref type name, in which
        /// case this object's <code>ref</code> field will be set to an
        /// instance of that implementation-specific class.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
        private void ReadObject(java.io.ObjectInputStream @in)
        {
            String refClassName = @in.ReadUTF();

            if (refClassName == null || refClassName.Length() == 0)
            {
                /*
                 * No reference class name specified, so construct
                 * remote reference from its serialized form.
                 */
                @ref = (RemoteRef)@in.ReadObject();
            }
            else
            {
                /*
                 * Built-in reference class specified, so delegate to
                 * internal reference class to initialize its fields from
                 * its external form.
                 */
                String internalRefClassName = RemoteRef_Fields.PackagePrefix + "." + refClassName;
                Class  refClass             = Class.ForName(internalRefClassName);
                try
                {
                    @ref = (RemoteRef)refClass.NewInstance();

                    /*
                     * If this step fails, assume we found an internal
                     * class that is not meant to be a serializable ref
                     * type.
                     */
                }
                catch (InstantiationException e)
                {
                    throw new ClassNotFoundException(internalRefClassName, e);
                }
                catch (IllegalAccessException e)
                {
                    throw new ClassNotFoundException(internalRefClassName, e);
                }
                catch (ClassCastException e)
                {
                    throw new ClassNotFoundException(internalRefClassName, e);
                }
                @ref.ReadExternal(@in);
            }
        }
 public virtual void TestSerializeEnvelope2D()
 {
     try
     {
         java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream    oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.Envelope2D   env       = new com.epl.geometry.Envelope2D(1.213948734, 2.213948734, 11.213948734, 12.213948734);
         oo.WriteObject(env);
         System.IO.BinaryWriter      streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream   ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.Envelope2D envRes   = (com.epl.geometry.Envelope2D)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(envRes.Equals(env));
     }
     catch (System.Exception)
     {
         Fail("Envelope2D serialization failure");
     }
     //		try
     //		{
     //			 FileOutputStream streamOut = new FileOutputStream(
     //			 "c:/temp/savedEnvelope2D.txt");
     //			 ObjectOutputStream oo = new ObjectOutputStream(streamOut);
     //			 Envelope2D e = new Envelope2D(177.123, 188.234, 999.122, 888.999);
     //			 oo.writeObject(e);
     //		 }
     //		 catch(Exception ex)
     //		 {
     //		   fail("Envelope2D serialization failure");
     //		 }
     try
     {
         java.io.InputStream         s  = typeof(com.epl.geometry.TestSerialization).GetResourceAsStream("savedEnvelope2D.txt");
         java.io.ObjectInputStream   ii = new java.io.ObjectInputStream(s);
         com.epl.geometry.Envelope2D e  = (com.epl.geometry.Envelope2D)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(e != null);
         NUnit.Framework.Assert.IsTrue(e.Equals(new com.epl.geometry.Envelope2D(177.123, 188.234, 999.122, 888.999)));
     }
     catch (System.Exception)
     {
         Fail("Envelope2D serialization failure");
     }
 }
 public virtual void TestSerializeLine()
 {
     try
     {
         java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream    oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.Line         pt        = new com.epl.geometry.Line();
         pt.SetStart(new com.epl.geometry.Point(10, 30));
         pt.SetEnd(new com.epl.geometry.Point(120, 40));
         oo.WriteObject(pt);
         System.IO.BinaryWriter    streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.Line     ptRes    = (com.epl.geometry.Line)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception ex)
     {
         // fail("Line serialization failure");
         NUnit.Framework.Assert.AreEqual(ex.Message, "Cannot serialize this geometry");
     }
 }
Exemple #7
0
        /// <summary>
        /// readObject is called to restore the state of the StringBuffer from
        /// a stream.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException
        private void ReadObject(java.io.ObjectInputStream s)
        {
            s.DefaultReadObject();
            Count         = s.ReadInt();
            Value_Renamed = (char[])s.ReadObject();
        }
 public virtual void TestSerializeSR()
 {
     try
     {
         java.io.ByteArrayOutputStream     streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream        oo        = new java.io.ObjectOutputStream(streamOut);
         com.epl.geometry.SpatialReference sr        = com.epl.geometry.SpatialReference.Create(102100);
         oo.WriteObject(sr);
         System.IO.BinaryWriter            streamIn = new System.IO.BinaryWriter(streamOut.ToByteArray());
         java.io.ObjectInputStream         ii       = new java.io.ObjectInputStream(streamIn);
         com.epl.geometry.SpatialReference ptRes    = (com.epl.geometry.SpatialReference)ii.ReadObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(sr));
     }
     catch (System.Exception)
     {
         Fail("Spatial Reference serialization failure");
     }
 }
Exemple #9
0
        /// <summary>
        /// Restores this object from a stream (i.e., deserializes it).
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, ClassNotFoundException
        private void ReadObject(java.io.ObjectInputStream ois)
        {
            CertificateFactory cf;
            Dictionary <String, CertificateFactory> cfs = null;

            ois.DefaultReadObject();             // location

            // process any new-style certs in the stream (if present)
            int size = ois.ReadInt();

            if (size > 0)
            {
                // we know of 3 different cert types: X.509, PGP, SDSI, which
                // could all be present in the stream at the same time
                cfs        = new Dictionary <String, CertificateFactory>(3);
                this.Certs = new java.security.cert.Certificate[size];
            }

            for (int i = 0; i < size; i++)
            {
                // read the certificate type, and instantiate a certificate
                // factory of that type (reuse existing factory if possible)
                String certType = ois.ReadUTF();
                if (cfs.ContainsKey(certType))
                {
                    // reuse certificate factory
                    cf = cfs[certType];
                }
                else
                {
                    // create new certificate factory
                    try
                    {
                        cf = CertificateFactory.GetInstance(certType);
                    }
                    catch (CertificateException)
                    {
                        throw new ClassNotFoundException("Certificate factory for " + certType + " not found");
                    }
                    // store the certificate factory so we can reuse it later
                    cfs[certType] = cf;
                }
                // parse the certificate
                sbyte[] encoded = null;
                try
                {
                    encoded = new sbyte[ois.ReadInt()];
                }
                catch (OutOfMemoryError)
                {
                    throw new IOException("Certificate too big");
                }
                ois.ReadFully(encoded);
                ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
                try
                {
                    this.Certs[i] = cf.GenerateCertificate(bais);
                }
                catch (CertificateException ce)
                {
                    throw new IOException(ce.Message);
                }
                bais.Close();
            }

            // Deserialize array of code signers (if any)
            try
            {
                this.Signers = ((CodeSigner[])ois.ReadObject()).clone();
            }
            catch (IOException)
            {
                // no signers present
            }
        }