Пример #1
0
        public List <string> Classify(string model, string test)
        {
            List <string> ret = new List <string>();

            try
            {
                java.io.ObjectInputStream   ois = new java.io.ObjectInputStream(new java.io.FileInputStream(model));
                weka.classifiers.Classifier cl  = (weka.classifiers.Classifier)ois.readObject();
                ois.close();

                weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader(test));
                insts.setClassIndex(insts.numAttributes() - 1);
                for (int i = 0; i < 1; i++)
                {
                    weka.core.Instance currentInst    = insts.instance(i);
                    double             predictedClass = cl.classifyInstance(currentInst);
                    double[]           distrs         = cl.distributionForInstance(currentInst);
                    //string actual = insts.classAttribute().value((int)currentInst.classValue());
                    //string predicted = insts.classAttribute().value((int)predictedClass);
                    // System.Console.WriteLine("ID: " + (i + 1) + ", " + predicted);
                    for (int j = 0; j < distrs.Length; j++)
                    {
                        string predicted = insts.classAttribute().value(j);
                        string distr     = distrs[j].ToString("#0.000");
                        ret.Add(predicted + "," + distr);
                    }
                }
                return(ret);
            }
            catch
            {
                return(ret);
            }
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="java.lang.ClassNotFoundException"></exception>
        private void readObject(java.io.ObjectInputStream stream)
        {
            stream.defaultReadObject();
            char inSeparator = stream.readChar();

            this.path = fixSlashes(path.Replace(inSeparator, separatorChar));
        }
Пример #3
0
        /// <summary>
        /// readObject is called to restore the state of the SignedObject 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)
        {
            java.io.ObjectInputStream.GetField fields = s.ReadFields();
            Content           = ((sbyte[])fields.Get("content", null)).clone();
            Signature_Renamed = ((sbyte[])fields.Get("signature", null)).clone();
            Thealgorithm      = (String)fields.Get("thealgorithm", null);
        }
Пример #4
0
        private void readObject(java.io.ObjectInputStream ois)
        {
            try
            {
                m_modelData = null;
                InitFileNames();

                int version = ois.readInt();
                if (version == 2)
                {
                    int n = ois.readInt();
                    m_modelData = new byte[n];
                    int m = 0;
                    while (true)
                    {
                        int mm = ois.read(m_modelData, m, n - m);
                        m += mm;
                        if (m >= n)
                        {
                            break;
                        }
                    }
                    ois.readBoolean();
                    m_delta = ois.readDouble();

                    System.IO.File.WriteAllBytes(m_modelFile, m_modelData);
                }
                else if (version == 3)
                {
                    int n = ois.readInt();
                    m_modelData = new byte[n];
                    int m = 0;
                    while (true)
                    {
                        int mm = ois.read(m_modelData, m, n - m);
                        m += mm;
                        if (m >= n)
                        {
                            break;
                        }
                    }
                    Boolean b = ois.readBoolean();
                    if (b)
                    {
                        m_mustValue = ois.readInt();
                    }
                    else
                    {
                        ois.readInt();
                    }
                    m_delta = ois.readDouble();

                    System.IO.File.WriteAllBytes(m_modelFile, m_modelData);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #5
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="java.lang.ClassNotFoundException"></exception>
        private void readObject(java.io.ObjectInputStream @in)
        {
            java.io.ObjectInputStream.GetField fields = @in.readFields();
            int count = fields.get("count", 0);

            char[] value = (char[])fields.get("value", null);
            set(value, count);
        }
Пример #6
0
        /// <summary>
        /// Reads the state of a
        /// <code>StringBuilder</code>
        /// from the passed stream and
        /// restores it to this instance.
        /// </summary>
        /// <param name="in">the stream to read the state from.</param>
        /// <exception cref="System.IO.IOException">if the stream throws it during the read.</exception>
        /// <exception cref="ClassNotFoundException">if the stream throws it during the read.
        ///     </exception>
        /// <exception cref="java.lang.ClassNotFoundException"></exception>
        private void readObject(java.io.ObjectInputStream @in)
        {
            @in.defaultReadObject();
            int count = @in.readInt();

            char[] value = (char[])@in.readObject();
            set(value, count);
        }
Пример #7
0
 public void Load(Stream stream)
 {
     //FileInputStream stream = new FileInputStream(filePath);
     java.io.InputStream _javaStream = DroolsDotnetUtil.getJavaInputStreamFromSystemStream(stream);
     java.io.ObjectInput objInp      = new java.io.ObjectInputStream(_javaStream);
     ((ReteooRuleBase)this._javaRuleBase).readExternal(objInp);
     _javaStream.close();
 }
Пример #8
0
 public void Load(Stream stream)
 {
     //FileInputStream stream = new FileInputStream(filePath);
     java.io.InputStream _javaStream = DroolsDotnetUtil.getJavaInputStreamFromSystemStream(stream);
     java.io.ObjectInput objInp = new java.io.ObjectInputStream(_javaStream);
     ((ReteooRuleBase)this._javaRuleBase).readExternal(objInp);
     _javaStream.close();
 }
 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");
     }
 }
Пример #10
0
        internal static void readObject(Exception x, ObjectInputStream s)
        {
#if !FIRST_PASS
            ObjectInputStream.GetField fields = s.readFields();
            initThrowable(x, fields.get("detailMessage", null), fields.get("cause", null));
            StackTraceElement[] stackTrace = (StackTraceElement[])fields.get("stackTrace", null);
            Throwable.instancehelper_setStackTrace(x, stackTrace == null ? new StackTraceElement[0] : stackTrace);
#endif
        }
 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");
     }
 }
Пример #13
0
 public virtual void testSerializePolyline()
 {
     try
     {
         java.io.ByteArrayOutputStream   streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream      oo        = new java.io.ObjectOutputStream(streamOut);
         com.esri.core.geometry.Polyline pt        = new com.esri.core.geometry.Polyline();
         pt.startPath(10, 10);
         pt.lineTo(100, 100);
         pt.lineTo(200, 100);
         oo.writeObject(pt);
         java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut
                                                                                  .toByteArray());
         java.io.ObjectInputStream       ii    = new java.io.ObjectInputStream(streamIn);
         com.esri.core.geometry.Polyline ptRes = (com.esri.core.geometry.Polyline)ii.readObject
                                                     ();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception)
     {
         fail("Polyline serialization failure");
     }
     // try
     // {
     // FileOutputStream streamOut = new FileOutputStream(m_thisDirectory +
     // "savedPolyline.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 = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization
                                                                        )).getResourceAsStream("savedPolyline.txt");
         java.io.ObjectInputStream       ii    = new java.io.ObjectInputStream(s);
         com.esri.core.geometry.Polyline ptRes = (com.esri.core.geometry.Polyline)ii.readObject
                                                     ();
         NUnit.Framework.Assert.IsTrue(ptRes != null);
     }
     catch (System.Exception)
     {
         fail("Polyline serialization failure");
     }
 }
Пример #14
0
 public virtual void testSerializeMultiPoint()
 {
     try
     {
         java.io.ByteArrayOutputStream     streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream        oo        = new java.io.ObjectOutputStream(streamOut);
         com.esri.core.geometry.MultiPoint pt        = new com.esri.core.geometry.MultiPoint();
         pt.add(10, 30);
         pt.add(120, 40);
         oo.writeObject(pt);
         java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut
                                                                                  .toByteArray());
         java.io.ObjectInputStream         ii    = new java.io.ObjectInputStream(streamIn);
         com.esri.core.geometry.MultiPoint ptRes = (com.esri.core.geometry.MultiPoint)ii.readObject
                                                       ();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt));
     }
     catch (System.Exception)
     {
         fail("MultiPoint serialization failure");
     }
     // try
     // {
     // FileOutputStream streamOut = new FileOutputStream(m_thisDirectory +
     // "savedMultiPoint.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 = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization
                                                                        )).getResourceAsStream("savedMultiPoint.txt");
         java.io.ObjectInputStream         ii    = new java.io.ObjectInputStream(s);
         com.esri.core.geometry.MultiPoint ptRes = (com.esri.core.geometry.MultiPoint)ii.readObject
                                                       ();
         NUnit.Framework.Assert.IsTrue(ptRes.getPoint(1).getY() == 40);
     }
     catch (System.Exception)
     {
         fail("MultiPoint serialization failure");
     }
 }
Пример #15
0
        /// <summary>
        /// Reconstitutes the instance from a stream (that is, deserializes it).
        /// </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, java.io.InvalidObjectException
        private void ReadObject(java.io.ObjectInputStream s)
        {
            // Note: This must be changed if any additional fields are defined
            Object a = s.ReadFields().Get("array", null);

            if (a == null || !a.GetType().IsArray)
            {
                throw new java.io.InvalidObjectException("Not array type");
            }
            if (a.GetType() != typeof(Object[]))
            {
                a = Arrays.CopyOf((Object[])a, Array.getLength(a), typeof(Object[]));
            }
            @unsafe.putObjectVolatile(this, ArrayFieldOffset, a);
        }
Пример #16
0
        // Private methods

        /// <summary>
        /// Reconstitute the {@code MathContext} instance from a stream (that is,
        /// deserialize it).
        /// </summary>
        /// <param name="s"> the stream being read. </param>
//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();             // read in all fields
            // validate possibly bad fields
            if (Precision_Renamed < MIN_DIGITS)
            {
                String message = "MathContext: invalid digits in stream";
                throw new java.io.StreamCorruptedException(message);
            }
            if (RoundingMode_Renamed == null)
            {
                String message = "MathContext: null roundingMode in stream";
                throw new java.io.StreamCorruptedException(message);
            }
        }
Пример #17
0
 public virtual void testSerializeEnvelope2D()
 {
     try
     {
         java.io.ByteArrayOutputStream     streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream        oo        = new java.io.ObjectOutputStream(streamOut);
         com.esri.core.geometry.Envelope2D env       = new com.esri.core.geometry.Envelope2D(1.213948734
                                                                                             , 2.213948734, 11.213948734, 12.213948734);
         oo.writeObject(env);
         java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut
                                                                                  .toByteArray());
         java.io.ObjectInputStream         ii     = new java.io.ObjectInputStream(streamIn);
         com.esri.core.geometry.Envelope2D envRes = (com.esri.core.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 = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization
                                                                        )).getResourceAsStream("savedEnvelope2D.txt");
         java.io.ObjectInputStream         ii = new java.io.ObjectInputStream(s);
         com.esri.core.geometry.Envelope2D e  = (com.esri.core.geometry.Envelope2D)ii.readObject
                                                    ();
         NUnit.Framework.Assert.IsTrue(e != null);
         NUnit.Framework.Assert.IsTrue(e.Equals(new com.esri.core.geometry.Envelope2D(177.123
                                                                                      , 188.234, 999.122, 888.999)));
     }
     catch (System.Exception)
     {
         fail("Envelope2D serialization failure");
     }
 }
Пример #18
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);
            }
        }
Пример #19
0
 public static object readObjectFromFile(string fileName)
 {
     try
     {
         java.io.File f = new java.io.File(fileName);
         f.setReadable(true);
         java.io.FileInputStream   streamIn = new java.io.FileInputStream(f);
         java.io.ObjectInputStream ii       = new java.io.ObjectInputStream(streamIn);
         object obj = ii.readObject();
         streamIn.close();
         return(obj);
     }
     catch (System.Exception)
     {
         return(null);
     }
 }
Пример #20
0
        public void Test2()
        {
            java.io.ObjectInputStream   ois = new java.io.ObjectInputStream(new java.io.FileInputStream("D:\\android_analysis\\som_model.model"));
            weka.classifiers.Classifier cl  = (weka.classifiers.Classifier)ois.readObject();
            ois.close();

            weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader("D:\\android_analysis\\test1.arff"));
            insts.setClassIndex(insts.numAttributes() - 1);
            for (int i = 0; i < insts.numInstances(); i++)
            {
                weka.core.Instance currentInst    = insts.instance(i);
                double             predictedClass = cl.classifyInstance(currentInst);
                double[]           distrs         = cl.distributionForInstance(currentInst);
                //string actual = insts.classAttribute().value((int)currentInst.classValue());
                //string predicted = insts.classAttribute().value((int)predictedClass);
                // System.Console.WriteLine("ID: " + (i + 1) + ", " + predicted);
            }
        }
 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");
     }
 }
Пример #22
0
 public virtual void testSerializeSR()
 {
     try
     {
         java.io.ByteArrayOutputStream           streamOut = new java.io.ByteArrayOutputStream();
         java.io.ObjectOutputStream              oo        = new java.io.ObjectOutputStream(streamOut);
         com.esri.core.geometry.SpatialReference sr        = com.esri.core.geometry.SpatialReference
                                                             .create(102100);
         oo.writeObject(sr);
         java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut
                                                                                  .toByteArray());
         java.io.ObjectInputStream ii = new java.io.ObjectInputStream(streamIn);
         com.esri.core.geometry.SpatialReference ptRes = (com.esri.core.geometry.SpatialReference
                                                          )ii.readObject();
         NUnit.Framework.Assert.IsTrue(ptRes.Equals(sr));
     }
     catch (System.Exception)
     {
         fail("Spatial Reference 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");
     }
 }
Пример #24
0
        protected object GetStateFromClient(FacesContext facesContext, String viewId, String renderKitId)
        {
            //RenderKit renderKit = RenderKitFactory.getRenderKit (facesContext, renderKitId);
            //ResponseStateManager responseStateManager = renderKit.getResponseStateManager ();
            //responseStateManager.getTreeStructureToRestore (facesContext, viewId); //ignore result. Must call for compatibility with sun implementation.
            //return responseStateManager.getComponentStateToRestore (facesContext);

            java.util.Map map = facesContext.getExternalContext().getRequestParameterMap();
            string        s1  = (string)map.get(VIEWSTATE);

            byte [] buffer = Convert.FromBase64String(s1);
            java.io.ByteArrayInputStream bytearrayinputstream = new java.io.ByteArrayInputStream(vmw.common.TypeUtils.ToSByteArray(buffer));
            java.io.ObjectInputStream    inputStream          = new java.io.ObjectInputStream(bytearrayinputstream);
            //ignore tree structure
            //inputStream.readObject ();
            object state = inputStream.readObject();

            inputStream.close();
            bytearrayinputstream.close();

            return(state);
        }
            public int InitializeClassifier(string[] atributes, string[] gestures, string classAttribute, string modelLocation)
            {
                java.io.ObjectInputStream ois = new java.io.ObjectInputStream(new java.io.FileInputStream(modelLocation));


                m_cl = (weka.classifiers.Classifier)ois.readObject();

                //Declare the feature vector
                weka.core.FastVector fvWekaFeatureVector = new weka.core.FastVector(atributes.Length + 1);
                for (int i = 0; i < atributes.Length; i++)
                {
                    weka.core.Attribute aux = new weka.core.Attribute(atributes[i]);
                    fvWekaFeatureVector.addElement(aux);
                }


                //Declare the class weka.core.Attribute along with its values
                weka.core.FastVector fvClassValues = new weka.core.FastVector(gestures.Length);
                for (int i = 0; i < gestures.Length; i++)
                {
                    weka.core.Attribute z1 = new weka.core.Attribute(atributes[i]);
                    fvClassValues.addElement(gestures[i]);
                }
                //fvClassValues.addElement("yes");
                //fvClassValues.addElement("no");

                weka.core.Attribute ClassAttribute = new weka.core.Attribute(classAttribute, fvClassValues);

                fvWekaFeatureVector.addElement(ClassAttribute);

                dataSet = new weka.core.Instances("TestRel", fvWekaFeatureVector, 10);
                dataSet.setClassIndex(atributes.Length);

                testInstance = new weka.core.Instance(atributes.Length + 1);

                return(1);
            }
Пример #26
0
        }       //	create

        /// <summary>
        ///	Create from decoded hash map string
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="hexInput">hex string</param>
        /// <returns>issue</returns>
        //@SuppressWarnings("unchecked")

        public static MIssue Create(Ctx ctx, String hexInput)
        {
            Dictionary <String, String> hmIn = null;

            try                 //	encode inn report
            {
                byte[] byteArray = Secure.ConvertHexString(hexInput);
                java.io.ByteArrayInputStream bIn = new java.io.ByteArrayInputStream(byteArray);
                //MemoryStream bln = new MemoryStream(byteArray);

                java.io.ObjectInputStream oIn = new java.io.ObjectInputStream(bIn);
                //BufferedStream oIn = new BufferedStream(bln);
                hmIn = (Dictionary <String, String>)oIn.readObject();
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "", e);
                return(null);
            }

            MIssue issue = new MIssue(ctx, (Dictionary <String, String>)hmIn);

            return(issue);
        }       //	create
Пример #27
0
        /// <param name="s"> the stream </param>
        /// <exception cref="java.io.InvalidObjectException"> always </exception>
//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.InvalidObjectException
        private void ReadObject(java.io.ObjectInputStream s)
        {
            throw new java.io.InvalidObjectException("Proxy required");
        }
Пример #28
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();
        }
Пример #29
0
        internal static void readObject(Exception x, ObjectInputStream s)
        {
#if !FIRST_PASS
            lock (x)
            {
                // when you serialize a .NET exception it gets replaced by a com.sun.xml.internal.ws.developer.ServerSideException,
                // so we know that Exception is always a Throwable
                Throwable _this = (Throwable)x;

                // this the equivalent of s.defaultReadObject();
                ObjectInputStream.GetField fields = s.readFields();
                object          detailMessage     = fields.get("detailMessage", null);
                object          cause             = fields.get("cause", null);
                ConstructorInfo ctor = typeof(Throwable).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(Exception), typeof(bool), typeof(bool) }, null);
                if (cause == _this)
                {
                    ctor.Invoke(_this, new object[] { detailMessage, null, false, false });
                    _this.cause = _this;
                }
                else
                {
                    ctor.Invoke(_this, new object[] { detailMessage, cause, false, false });
                }
                _this.stackTrace           = (StackTraceElement[])fields.get("stackTrace", null);
                _this.suppressedExceptions = (java.util.List)fields.get("suppressedExceptions", null);

                // this is where the rest of the Throwable.readObject() code starts
                if (_this.suppressedExceptions != null)
                {
                    java.util.List suppressed = null;
                    if (_this.suppressedExceptions.isEmpty())
                    {
                        suppressed = Throwable.SUPPRESSED_SENTINEL;
                    }
                    else
                    {
                        suppressed = new java.util.ArrayList(1);
                        for (int i = 0; i < _this.suppressedExceptions.size(); i++)
                        {
                            Exception entry = (Exception)_this.suppressedExceptions.get(i);
                            if (entry == null)
                            {
                                throw new java.lang.NullPointerException("Cannot suppress a null exception.");
                            }
                            if (entry == _this)
                            {
                                throw new java.lang.IllegalArgumentException("Self-suppression not permitted");
                            }
                            suppressed.add(entry);
                        }
                    }
                    _this.suppressedExceptions = suppressed;
                }

                if (_this.stackTrace != null)
                {
                    if (_this.stackTrace.Length == 0)
                    {
                        _this.stackTrace = new StackTraceElement[0];
                    }
                    else if (_this.stackTrace.Length == 1 &&
                             java.lang.ThrowableHelper.SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(_this.stackTrace[0]))
                    {
                        _this.stackTrace = null;
                    }
                    else
                    {
                        foreach (StackTraceElement elem in _this.stackTrace)
                        {
                            if (elem == null)
                            {
                                throw new java.lang.NullPointerException("null StackTraceElement in serial stream. ");
                            }
                        }
                    }
                }
                else
                {
                    _this.stackTrace = new StackTraceElement[0];
                }
            }
#endif
        }
Пример #30
0
		protected object GetStateFromClient (FacesContext facesContext, String viewId, String renderKitId) {
			//RenderKit renderKit = RenderKitFactory.getRenderKit (facesContext, renderKitId);
			//ResponseStateManager responseStateManager = renderKit.getResponseStateManager ();
			//responseStateManager.getTreeStructureToRestore (facesContext, viewId); //ignore result. Must call for compatibility with sun implementation.
			//return responseStateManager.getComponentStateToRestore (facesContext);

			java.util.Map map = facesContext.getExternalContext ().getRequestParameterMap ();
			string s1 = (string) map.get (VIEWSTATE);

			byte [] buffer = Convert.FromBase64String (s1);
			java.io.ByteArrayInputStream bytearrayinputstream = new java.io.ByteArrayInputStream (vmw.common.TypeUtils.ToSByteArray (buffer));
			java.io.ObjectInputStream inputStream = new java.io.ObjectInputStream (bytearrayinputstream);
			//ignore tree structure
			//inputStream.readObject ();
			object state = inputStream.readObject ();
			inputStream.close ();
			bytearrayinputstream.close ();

			return state;
		}
Пример #31
0
 private void readObject(java.io.ObjectInputStream ois)
 {
     throw new System.NotImplementedException();
 }
Пример #32
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();

            if (Type == null)
            {
                throw new NullPointerException("type can't be null");
            }

            // 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();
            }
        }