Ejemplo n.º 1
0
        /// <summary>
        /// Read the ObjectInputStream and if it isn't null,
        /// add a listener to receive action events fired by the
        /// TextField.  Unrecognized keys or values will be
        /// ignored.
        /// </summary>
        /// <exception cref="HeadlessException"> if
        /// <code>GraphicsEnvironment.isHeadless()</code> returns
        /// <code>true</code> </exception>
        /// <seealso cref= #removeActionListener(ActionListener) </seealso>
        /// <seealso cref= #addActionListener(ActionListener) </seealso>
        /// <seealso cref= java.awt.GraphicsEnvironment#isHeadless </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException, HeadlessException
        private void ReadObject(ObjectInputStream s)
        {
            // HeadlessException will be thrown by TextComponent's readObject
            s.DefaultReadObject();

            // Make sure the state we just read in for columns has legal values
            if (Columns_Renamed < 0)
            {
                Columns_Renamed = 0;
            }

            // Read in listeners, if any
            Object keyOrNull;

            while (null != (keyOrNull = s.ReadObject()))
            {
                String key = ((String)keyOrNull).intern();

                if (ActionListenerK == key)
                {
                    AddActionListener((ActionListener)(s.ReadObject()));
                }
                else
                {
                    // skip value for unrecognized key
                    s.ReadObject();
                }
            }
        }
        /// <summary>Loads the model from disk.</summary>
        /// <param name="path">The location of model that was saved to disk</param>
        /// <exception cref="System.InvalidCastException">if model is the wrong format</exception>
        /// <exception cref="System.IO.IOException">
        /// if the model file doesn't exist or is otherwise
        /// unavailable/incomplete
        /// </exception>
        /// <exception cref="System.TypeLoadException">this would probably indicate a serious classpath problem</exception>
        public static Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor Load(string path, Type entityClassifier, bool preferDefaultGazetteer)
        {
            // load the additional arguments
            // try to load the extra file from the CLASSPATH first
            InputStream @is = typeof(Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor).GetClassLoader().GetResourceAsStream(path + ".extra");

            // if not found in the CLASSPATH, load from the file system
            if (@is == null)
            {
                @is = new FileInputStream(path + ".extra");
            }
            ObjectInputStream @in = new ObjectInputStream(@is);
            string            gazetteerLocation = ErasureUtils.UncheckedCast <string>(@in.ReadObject());

            if (preferDefaultGazetteer)
            {
                gazetteerLocation = DefaultPaths.DefaultNflGazetteer;
            }
            ICollection <string> annotationsToSkip = ErasureUtils.UncheckedCast <ICollection <string> >(@in.ReadObject());
            bool useSubTypes = ErasureUtils.UncheckedCast <bool>(@in.ReadObject());
            bool useBIO      = ErasureUtils.UncheckedCast <bool>(@in.ReadObject());

            @in.Close();
            @is.Close();
            Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor extractor = (Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor)MachineReading.MakeEntityExtractor(entityClassifier, gazetteerLocation);
            // load the CRF classifier (this works from any resource, e.g., classpath or file system)
            extractor.classifier = CRFClassifier.GetClassifier(path);
            // copy the extra arguments
            extractor.annotationsToSkip = annotationsToSkip;
            extractor.useSubTypes       = useSubTypes;
            extractor.useBIO            = useBIO;
            return(extractor);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deserializes this <code>DragSource</code>. This method first performs
        /// default deserialization. Next, this object's <code>FlavorMap</code> is
        /// deserialized by using the next object in the stream.
        /// If the resulting <code>FlavorMap</code> is <code>null</code>, this
        /// object's <code>FlavorMap</code> is set to the default FlavorMap for
        /// this thread's <code>ClassLoader</code>.
        /// Next, this object's listeners are deserialized by reading a
        /// <code>null</code>-terminated sequence of 0 or more key/value pairs
        /// from the stream:
        /// <ul>
        /// <li>If a key object is a <code>String</code> equal to
        /// <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is
        /// deserialized using the corresponding value object and added to this
        /// <code>DragSource</code>.
        /// <li>If a key object is a <code>String</code> equal to
        /// <code>dragSourceMotionListenerK</code>, a
        /// <code>DragSourceMotionListener</code> is deserialized using the
        /// corresponding value object and added to this <code>DragSource</code>.
        /// <li>Otherwise, the key/value pair is skipped.
        /// </ul>
        /// </summary>
        /// <seealso cref= java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap
        /// @since 1.4 </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
        private void ReadObject(ObjectInputStream s)
        {
            s.DefaultReadObject();

            // 'flavorMap' was written explicitly
            FlavorMap_Renamed = (FlavorMap)s.ReadObject();

            // Implementation assumes 'flavorMap' is never null.
            if (FlavorMap_Renamed == null)
            {
                FlavorMap_Renamed = SystemFlavorMap.DefaultFlavorMap;
            }

            Object keyOrNull;

            while (null != (keyOrNull = s.ReadObject()))
            {
                String key = ((String)keyOrNull).intern();

                if (DragSourceListenerK == key)
                {
                    AddDragSourceListener((DragSourceListener)(s.ReadObject()));
                }
                else if (DragSourceMotionListenerK == key)
                {
                    AddDragSourceMotionListener((DragSourceMotionListener)(s.ReadObject()));
                }
                else
                {
                    // skip value for unrecognized key
                    s.ReadObject();
                }
            }
        }
Ejemplo n.º 4
0
 public static IList <Tree> ConvertToTrees(byte[] input)
 {
     try
     {
         IList <Tree>         output = new List <Tree>();
         ByteArrayInputStream bis    = new ByteArrayInputStream(input);
         GZIPInputStream      gis    = new GZIPInputStream(bis);
         ObjectInputStream    ois    = new ObjectInputStream(gis);
         int size = ErasureUtils.UncheckedCast <int>(ois.ReadObject());
         for (int i = 0; i < size; ++i)
         {
             string rawTree = ErasureUtils.UncheckedCast(ois.ReadObject());
             Tree   tree    = Tree.ValueOf(rawTree, trf);
             tree.SetSpans();
             output.Add(tree);
         }
         ois.Close();
         gis.Close();
         bis.Close();
         return(output);
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(e);
     }
     catch (TypeLoadException e)
     {
         throw new Exception(e);
     }
 }
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private static Edu.Stanford.Nlp.Classify.MultinomialLogisticClassifier <LL, FF> Load <Ll, Ff>(string path)
        {
            System.Console.Error.Write("Loading classifier from " + path + "... ");
            ObjectInputStream @in = new ObjectInputStream(new FileInputStream(path));

            double[][]  myWeights      = ErasureUtils.UncheckedCast(@in.ReadObject());
            IIndex <FF> myFeatureIndex = ErasureUtils.UncheckedCast(@in.ReadObject());
            IIndex <LL> myLabelIndex   = ErasureUtils.UncheckedCast(@in.ReadObject());

            @in.Close();
            System.Console.Error.WriteLine("done.");
            return(new Edu.Stanford.Nlp.Classify.MultinomialLogisticClassifier <LL, FF>(myWeights, myFeatureIndex, myLabelIndex));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserializes this <code>DragSourceContext</code>. This method first
        /// performs default deserialization for all non-<code>transient</code>
        /// fields. This object's <code>Transferable</code> and
        /// <code>DragSourceListener</code> are then deserialized as well by using
        /// the next two objects in the stream. If the resulting
        /// <code>Transferable</code> is <code>null</code>, this object's
        /// <code>Transferable</code> is set to a dummy <code>Transferable</code>
        /// which supports no <code>DataFlavor</code>s.
        ///
        /// @since 1.4
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
        private void ReadObject(ObjectInputStream s)
        {
            ObjectInputStream.GetField f = s.ReadFields();

            DragGestureEvent newTrigger = (DragGestureEvent)f.Get("trigger", null);

            if (newTrigger == null)
            {
                throw new InvalidObjectException("Null trigger");
            }
            if (newTrigger.DragSource == null)
            {
                throw new InvalidObjectException("Null DragSource");
            }
            if (newTrigger.Component == null)
            {
                throw new InvalidObjectException("Null trigger component");
            }

            int newSourceActions = f.Get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);

            if (newSourceActions == DnDConstants.ACTION_NONE)
            {
                throw new InvalidObjectException("Invalid source actions");
            }
            int triggerActions = newTrigger.DragAction;

            if (triggerActions != DnDConstants.ACTION_COPY && triggerActions != DnDConstants.ACTION_MOVE && triggerActions != DnDConstants.ACTION_LINK)
            {
                throw new InvalidObjectException("No drag action");
            }
            Trigger_Renamed = newTrigger;

            Cursor_Renamed        = (Cursor)f.Get("cursor", null);
            UseCustomCursor       = f.Get("useCustomCursor", false);
            SourceActions_Renamed = newSourceActions;

            Transferable_Renamed = (Transferable)s.ReadObject();
            Listener             = (DragSourceListener)s.ReadObject();

            // Implementation assumes 'transferable' is never null.
            if (Transferable_Renamed == null)
            {
                if (EmptyTransferable == null)
                {
                    EmptyTransferable = new TransferableAnonymousInnerClassHelper(this);
                }
                Transferable_Renamed = EmptyTransferable;
            }
        }
Ejemplo n.º 7
0
        public virtual void TestReadWriteStreamFromString()
        {
            ObjectOutputStream oos = IOUtils.WriteStreamFromString(dirPath + "/objs.obj");

            oos.WriteObject(int.Parse(42));
            oos.WriteObject("forty two");
            oos.Close();
            ObjectInputStream ois = IOUtils.ReadStreamFromString(dirPath + "/objs.obj");
            object            i   = ois.ReadObject();
            object            s   = ois.ReadObject();

            NUnit.Framework.Assert.IsTrue(int.Parse(42).Equals(i));
            NUnit.Framework.Assert.IsTrue("forty two".Equals(s));
            ois.Close();
        }
        /// <summary>Returs a Tree from the server connected to at host:port.</summary>
        /// <exception cref="System.IO.IOException"/>
        public virtual Tree GetTree(string query)
        {
            Socket     socket = new Socket(host, port);
            TextWriter @out   = new OutputStreamWriter(socket.GetOutputStream(), "utf-8");

            @out.Write("tree " + query + "\n");
            @out.Flush();
            ObjectInputStream ois = new ObjectInputStream(socket.GetInputStream());
            object            o;

            try
            {
                o = ois.ReadObject();
            }
            catch (TypeLoadException e)
            {
                throw new Exception(e);
            }
            if (!(o is Tree))
            {
                throw new ArgumentException("Expected a tree");
            }
            Tree tree = (Tree)o;

            socket.Close();
            return(tree);
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
        private void ReadObject(ObjectInputStream s)
        {
            this.Map = new PropertyChangeListenerMap();

            ObjectInputStream.GetField fields = s.ReadFields();

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.Hashtable<String, PropertyChangeSupport> children = (java.util.Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
            Dictionary <String, PropertyChangeSupport> children = (Dictionary <String, PropertyChangeSupport>)fields.Get("children", null);

            this.Source = fields.Get("source", null);
            fields.Get("propertyChangeSupportSerializedDataVersion", 2);

            Object listenerOrNull;

            while (null != (listenerOrNull = s.ReadObject()))
            {
                this.Map.Add(null, (PropertyChangeListener)listenerOrNull);
            }
            if (children != null)
            {
                foreach (Map_Entry <String, PropertyChangeSupport> entry in children)
                {
                    foreach (PropertyChangeListener listener in entry.Value.PropertyChangeListeners)
                    {
                        this.Map.Add(entry.Key, listener);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Deserializes this <code>DropTarget</code>. This method first performs
        /// default deserialization for all non-<code>transient</code> fields. An
        /// attempt is then made to deserialize this object's
        /// <code>DropTargetListener</code> as well. This is first attempted by
        /// deserializing the field <code>dtListener</code>, because, in releases
        /// prior to 1.4, a non-<code>transient</code> field of this name stored the
        /// <code>DropTargetListener</code>. If this fails, the next object in the
        /// stream is used instead.
        ///
        /// @since 1.4
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
        private void ReadObject(ObjectInputStream s)
        {
            ObjectInputStream.GetField f = s.ReadFields();

            try
            {
                DropTargetContext_Renamed = (DropTargetContext)f.Get("dropTargetContext", null);
            }
            catch (IllegalArgumentException)
            {
                // Pre-1.4 support. 'dropTargetContext' was previously transient
            }
            if (DropTargetContext_Renamed == null)
            {
                DropTargetContext_Renamed = CreateDropTargetContext();
            }

            Component_Renamed = (Component)f.Get("component", null);
            Actions           = f.Get("actions", DnDConstants.ACTION_COPY_OR_MOVE);
            Active_Renamed    = f.Get("active", true);

            // Pre-1.4 support. 'dtListener' was previously non-transient
            try
            {
                DtListener = (DropTargetListener)f.Get("dtListener", null);
            }
            catch (IllegalArgumentException)
            {
                // 1.4-compatible byte stream. 'dtListener' was written explicitly
                DtListener = (DropTargetListener)s.ReadObject();
            }
        }
Ejemplo n.º 11
0
 /*
  * public Set<Integer> getPatterns(String sentId, Integer tokenId) throws SQLException, IOException, ClassNotFoundException {
  * if(useDBForTokenPatterns){
  * Connection conn = SQLConnection.getConnection();
  *
  * String query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\' and tokenid = " + tokenId;
  * Statement stmt = conn.createStatement();
  * ResultSet rs = stmt.executeQuery(query);
  * Set<Integer> pats = null;
  * if(rs.next()){
  * byte[] st = (byte[]) rs.getObject(1);
  * ByteArrayInputStream baip = new ByteArrayInputStream(st);
  * ObjectInputStream ois = new ObjectInputStream(baip);
  * pats = (Set<Integer>) ois.readObject();
  *
  * }
  * conn.close();
  * return pats;
  * }
  * else
  * return patternsForEachToken.get(sentId).get(tokenId);
  * }*/
 public override IDictionary <int, ICollection <E> > GetPatternsForAllTokens(string sentId)
 {
     try
     {
         IConnection conn = SQLConnection.GetConnection();
         //Map<Integer, Set<Integer>> pats = new ConcurrentHashMap<Integer, Set<Integer>>();
         string     query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\'";
         IStatement stmt  = conn.CreateStatement();
         IResultSet rs    = stmt.ExecuteQuery(query);
         IDictionary <int, ICollection <E> > patsToken = new Dictionary <int, ICollection <E> >();
         if (rs.Next())
         {
             byte[] st = (byte[])rs.GetObject(1);
             ByteArrayInputStream baip = new ByteArrayInputStream(st);
             ObjectInputStream    ois  = new ObjectInputStream(baip);
             patsToken = (IDictionary <int, ICollection <E> >)ois.ReadObject();
         }
         //pats.put(rs.getInt("tokenid"), patsToken);
         conn.Close();
         return(patsToken);
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 12
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private static void DemonstrateSerialization()
        {
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Demonstrating working with a serialized classifier");
            ColumnDataClassifier         cdc = new ColumnDataClassifier(where + "examples/cheese2007.prop");
            IClassifier <string, string> cl  = cdc.MakeClassifier(cdc.ReadTrainingExamples(where + "examples/cheeseDisease.train"));

            // Exhibit serialization and deserialization working. Serialized to bytes in memory for simplicity
            System.Console.Out.WriteLine();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream    oos  = new ObjectOutputStream(baos);

            oos.WriteObject(cl);
            oos.Close();
            byte[] @object                       = baos.ToByteArray();
            ByteArrayInputStream bais            = new ByteArrayInputStream(@object);
            ObjectInputStream    ois             = new ObjectInputStream(bais);
            LinearClassifier <string, string> lc = ErasureUtils.UncheckedCast(ois.ReadObject());

            ois.Close();
            ColumnDataClassifier cdc2 = new ColumnDataClassifier(where + "examples/cheese2007.prop");

            // We compare the output of the deserialized classifier lc versus the original one cl
            // For both we use a ColumnDataClassifier to convert text lines to examples
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Making predictions with both classifiers");
            foreach (string line in ObjectBank.GetLineIterator(where + "examples/cheeseDisease.test", "utf-8"))
            {
                IDatum <string, string> d  = cdc.MakeDatumFromLine(line);
                IDatum <string, string> d2 = cdc2.MakeDatumFromLine(line);
                System.Console.Out.Printf("%s  =origi=>  %s (%.4f)%n", line, cl.ClassOf(d), cl.ScoresOf(d).GetCount(cl.ClassOf(d)));
                System.Console.Out.Printf("%s  =deser=>  %s (%.4f)%n", line, lc.ClassOf(d2), lc.ScoresOf(d).GetCount(lc.ClassOf(d)));
            }
        }
Ejemplo n.º 13
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        public virtual IDictionary <string, double[]> GetEmbeddings(string cacheFilename, IList <CoNLLBenchmark.CoNLLSentence> sentences)
        {
            File f = new File(cacheFilename);
            IDictionary <string, double[]> trimmedSet;

            if (!f.Exists())
            {
                trimmedSet = new Dictionary <string, double[]>();
                IDictionary <string, double[]> massiveSet = LoadEmbeddingsFromFile("../google-300.txt");
                log.Info("Got massive embedding set size " + massiveSet.Count);
                foreach (CoNLLBenchmark.CoNLLSentence sentence in sentences)
                {
                    foreach (string token in sentence.token)
                    {
                        if (massiveSet.Contains(token))
                        {
                            trimmedSet[token] = massiveSet[token];
                        }
                    }
                }
                log.Info("Got trimmed embedding set size " + trimmedSet.Count);
                f.CreateNewFile();
                ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(cacheFilename)));
                oos.WriteObject(trimmedSet);
                oos.Close();
                log.Info("Wrote trimmed set to file");
            }
            else
            {
                ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(cacheFilename)));
                trimmedSet = (IDictionary <string, double[]>)ois.ReadObject();
                ois.Close();
            }
            return(trimmedSet);
        }
 public override IDictionary <int, ICollection <E> > GetPatternsForAllTokens(string sentId)
 {
     try
     {
         TermQuery query = new TermQuery(new Term("sentid", sentId));
         TopDocs   tp    = searcher.Search(query, 1);
         if (tp.totalHits > 0)
         {
             foreach (ScoreDoc s in tp.scoreDocs)
             {
                 int docId = s.doc;
                 Org.Apache.Lucene.Document.Document d = searcher.Doc(docId);
                 byte[] st = d.GetBinaryValue("patterns").bytes;
                 ByteArrayInputStream baip = new ByteArrayInputStream(st);
                 ObjectInputStream    ois  = new ObjectInputStream(baip);
                 return((IDictionary <int, ICollection <E> >)ois.ReadObject());
             }
         }
         else
         {
             throw new Exception("Why no patterns for sentid " + sentId + ". Number of documents in index are " + Size());
         }
     }
     catch (IOException e)
     {
         throw new Exception(e);
     }
     catch (TypeLoadException e)
     {
         throw new Exception(e);
     }
     return(null);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Deserialize the {@code CertificateRevokedException} instance.
        /// </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(ObjectInputStream ois)
        {
            // Read in the non-transient fields
            // (revocationDate, reason, authority)
            ois.DefaultReadObject();

            // Defensively copy the revocation date
            RevocationDate_Renamed = new DateTime(RevocationDate_Renamed.Ticks);

            // Read in the size (number of mappings) of the extensions map
            // and create the extensions map
            int size = ois.ReadInt();

            if (size == 0)
            {
                Extensions_Renamed = Collections.EmptyMap();
            }
            else
            {
                Extensions_Renamed = new Dictionary <String, Extension>(size);
            }

            // Read in the extensions and put the mappings in the extensions map
            for (int i = 0; i < size; i++)
            {
                String  oid      = (String)ois.ReadObject();
                bool    critical = ois.ReadBoolean();
                int     length   = ois.ReadInt();
                sbyte[] extVal   = new sbyte[length];
                ois.ReadFully(extVal);
                Extension ext = sun.security.x509.Extension.newExtension(new ObjectIdentifier(oid), critical, extVal);
                Extensions_Renamed[oid] = ext;
            }
        }
Ejemplo n.º 16
0
 // no header
 /// <exception cref="System.IO.IOException"/>
 public virtual T Deserialize(T @object)
 {
     try
     {
         // ignore passed-in object
         return((T)ois.ReadObject());
     }
     catch (TypeLoadException e)
     {
         throw new IOException(e.ToString());
     }
 }
Ejemplo n.º 17
0
        /*
         * Reads the <code>ObjectInputStream</code> and if it
         * isn't <code>null</code> adds a listener to receive
         * item events fired by the <code>Checkbox</code> menu item.
         * Unrecognized keys or values will be ignored.
         *
         * @param s the <code>ObjectInputStream</code> to read
         * @serial
         * @see removeActionListener()
         * @see addActionListener()
         * @see #writeObject
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
        private void ReadObject(ObjectInputStream s)
        {
            s.DefaultReadObject();

            Object keyOrNull;

            while (null != (keyOrNull = s.ReadObject()))
            {
                String key = ((String)keyOrNull).intern();

                if (ItemListenerK == key)
                {
                    AddItemListener((ItemListener)(s.ReadObject()));
                }

                else         // skip value for unrecognized key
                {
                    s.ReadObject();
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Reads the <code>ObjectInputStream</code> and if
        /// it isn't <code>null</code> adds a listener to
        /// receive action events fired by the button.
        /// Unrecognized keys or values will be ignored.
        /// </summary>
        /// <param name="s"> the <code>ObjectInputStream</code> to read </param>
        /// <exception cref="HeadlessException"> if
        ///   <code>GraphicsEnvironment.isHeadless</code> returns
        ///   <code>true</code>
        /// @serial </exception>
        /// <seealso cref= #removeActionListener(ActionListener) </seealso>
        /// <seealso cref= #addActionListener(ActionListener) </seealso>
        /// <seealso cref= java.awt.GraphicsEnvironment#isHeadless </seealso>
        /// <seealso cref= #writeObject(ObjectOutputStream) </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException, HeadlessException
        private void ReadObject(ObjectInputStream s)
        {
            GraphicsEnvironment.CheckHeadless();
            s.DefaultReadObject();

            Object keyOrNull;

            while (null != (keyOrNull = s.ReadObject()))
            {
                String key = ((String)keyOrNull).intern();

                if (ActionListenerK == key)
                {
                    AddActionListener((ActionListener)(s.ReadObject()));
                }

                else         // skip value for unrecognized key
                {
                    s.ReadObject();
                }
            }
        }
Ejemplo n.º 19
0
 protected Java.Lang.Object ConvertFromBytes(byte[] bytes)
 {
     using (var ms = new MemoryStream())
         using (var ois = new ObjectInputStream(ms))
         {
             //var binForm = new BinaryFormatter();
             //memStream.Write(bytes, 0, bytes.Length);
             //memStream.Seek(0, SeekOrigin.Begin);
             //var obj = binForm.Deserialize(memStream);
             //return obj;
             return(ois.ReadObject());
         }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Reads the <code>ObjectInputStream</code> and if it
        /// isn't <code>null</code> adds a listener to receive
        /// action events fired by the <code>Menu</code> Item.
        /// Unrecognized keys or values will be ignored.
        /// </summary>
        /// <param name="s"> the <code>ObjectInputStream</code> to read </param>
        /// <exception cref="HeadlessException"> if
        ///   <code>GraphicsEnvironment.isHeadless</code> returns
        ///   <code>true</code> </exception>
        /// <seealso cref= #removeActionListener(ActionListener) </seealso>
        /// <seealso cref= #addActionListener(ActionListener) </seealso>
        /// <seealso cref= #writeObject(ObjectOutputStream) </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException, HeadlessException
        private void ReadObject(ObjectInputStream s)
        {
            // HeadlessException will be thrown from MenuComponent's readObject
            s.DefaultReadObject();

            Object keyOrNull;

            while (null != (keyOrNull = s.ReadObject()))
            {
                String key = ((String)keyOrNull).intern();

                if (ActionListenerK == key)
                {
                    AddActionListener((ActionListener)(s.ReadObject()));
                }

                else         // skip value for unrecognized key
                {
                    s.ReadObject();
                }
            }
        }
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.TypeLoadException"/>
 public AnCoraProcessor(IList <File> inputFiles, Properties options)
 {
     this.inputFiles = inputFiles;
     this.options    = options;
     if (options.Contains("unigramTagger"))
     {
         ObjectInputStream ois = new ObjectInputStream(new FileInputStream(options.GetProperty("unigramTagger")));
         unigramTagger = (TwoDimensionalCounter <string, string>)ois.ReadObject();
     }
     else
     {
         unigramTagger = new TwoDimensionalCounter <string, string>();
     }
 }
Ejemplo n.º 22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
        private void ReadObject(ObjectInputStream @in)
        {
            // We have to call defaultReadObject first.
            @in.DefaultReadObject();

            // Read version number.
            sbyte major = @in.ReadByte();
            sbyte minor = @in.ReadByte();

            if (major != 1)
            {
                throw new IOException("LogRecord: bad version: " + major + "." + minor);
            }
            int len = @in.ReadInt();

            if (len == -1)
            {
                Parameters_Renamed = null;
            }
            else
            {
                Parameters_Renamed = new Object[len];
                for (int i = 0; i < Parameters_Renamed.Length; i++)
                {
                    Parameters_Renamed[i] = @in.ReadObject();
                }
            }
            // If necessary, try to regenerate the resource bundle.
            if (ResourceBundleName_Renamed != null)
            {
                try
                {
                    // use system class loader to ensure the ResourceBundle
                    // instance is a different instance than null loader uses
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), ClassLoader.getSystemClassLoader());
                    ResourceBundle bundle = ResourceBundle.GetBundle(ResourceBundleName_Renamed, Locale.Default, ClassLoader.SystemClassLoader);
                    ResourceBundle_Renamed = bundle;
                }
                catch (MissingResourceException)
                {
                    // This is not a good place to throw an exception,
                    // so we simply leave the resourceBundle null.
                    ResourceBundle_Renamed = null;
                }
            }

            NeedToInferCaller = false;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Deserialize this Object in a manner which is binary-compatible with
        /// the JDK.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private void ReadObject(ObjectInputStream s)
        {
            int    size;
            int    expectedMaxSize;
            object o;

            expectedMaxSize = s.ReadInt();
            size            = s.ReadInt();
            map             = new IdentityHashMap <E, bool>(expectedMaxSize);
            for (int i = 0; i < size; i++)
            {
                o = s.ReadObject();
                InternalAdd(ErasureUtils.UncheckedCast <E>(o));
            }
        }
Ejemplo n.º 24
0
 public T GetObject <T>(string key) where T : Java.Lang.Object
 {
     if (mSP.Contains(key))
     {
         string objectVal            = mSP.GetString(key, null);
         byte[] buffer               = Base64.Decode(objectVal, Base64Flags.Default);
         System.IO.MemoryStream bais = new System.IO.MemoryStream(buffer);
         ObjectInputStream      ois  = null;
         try
         {
             ois = new ObjectInputStream(bais);
             T t = (T)ois.ReadObject();
             return(t);
         }
         catch (StreamCorruptedException e)
         {
             e.PrintStackTrace();
         }
         catch (IOException e)
         {
             e.PrintStackTrace();
         }
         catch (ClassNotFoundException e)
         {
             e.PrintStackTrace();
         }
         finally
         {
             try
             {
                 if (bais != null)
                 {
                     bais.Close();
                 }
                 if (ois != null)
                 {
                     ois.Close();
                 }
             }
             catch (IOException e)
             {
                 e.PrintStackTrace();
             }
         }
     }
     return(null);
 }
 /// <summary>Returns cookie decoded from cookie string</summary>
 /// <param name="cookieString">string of cookie as returned from http request</param>
 /// <returns>decoded cookie or null if exception occured</returns>
 internal virtual Apache.Http.Cookie.Cookie DecodeCookie(string cookieString)
 {
     Apache.Http.Cookie.Cookie cookie = null;
     try
     {
         byte[] bytes = HexStringToByteArray(cookieString);
         ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
         ObjectInputStream    objectInputStream    = new ObjectInputStream(byteArrayInputStream);
         cookie = ((SerializableCookie)objectInputStream.ReadObject()).GetCookie();
     }
     catch (Exception exception)
     {
         Log.D(Log.TagSync, string.Format("decodeCookie failed.  encoded cookie: %s", cookieString
                                          ), exception);
     }
     return(cookie);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Deserializes this <code>DragGestureRecognizer</code>. This method first
        /// performs default deserialization for all non-<code>transient</code>
        /// fields. This object's <code>DragGestureListener</code> is then
        /// deserialized as well by using the next object in the stream.
        ///
        /// @since 1.4
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws ClassNotFoundException, java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        private void ReadObject(ObjectInputStream s)
        {
            ObjectInputStream.GetField f = s.ReadFields();

            DragSource newDragSource = (DragSource)f.Get("dragSource", null);

            if (newDragSource == null)
            {
                throw new InvalidObjectException("null DragSource");
            }
            DragSource_Renamed = newDragSource;

            Component_Renamed     = (Component)f.Get("component", null);
            SourceActions_Renamed = f.Get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
            Events = (List <InputEvent>)f.Get("events", new List <>(1));

            DragGestureListener = (DragGestureListener)s.ReadObject();
        }
Ejemplo n.º 27
0
 private bool Load(ObjectInputStream os)
 {
     try
     {
         lattices = (IList <Lattice>)os.ReadObject();
     }
     catch (IOException e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
         return(false);
     }
     catch (TypeLoadException e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 28
0
 public virtual void TestSerialization()
 {
     try
     {
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
         ObjectOutputStream    oout = new ObjectOutputStream(bout);
         oout.WriteObject(c1);
         byte[] bleh = bout.ToByteArray();
         ByteArrayInputStream    bin = new ByteArrayInputStream(bleh);
         ObjectInputStream       oin = new ObjectInputStream(bin);
         ClassicCounter <string> c3  = (ClassicCounter <string>)oin.ReadObject();
         NUnit.Framework.Assert.AreEqual(c3, c1);
     }
     catch (Exception e)
     {
         NUnit.Framework.Assert.Fail(e.Message);
     }
 }
Ejemplo n.º 29
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.TypeLoadException"></exception>
        private void ReadObject(ObjectInputStream @in)
        {
            string name  = (string)@in.ReadObject();
            string value = (string)@in.ReadObject();

            clientCookie = new BasicClientCookie(name, value);
            clientCookie.SetComment((string)@in.ReadObject());
            clientCookie.SetDomain((string)@in.ReadObject());
            clientCookie.SetExpiryDate((DateTime)@in.ReadObject());
            clientCookie.SetPath((string)@in.ReadObject());
            clientCookie.SetVersion(@in.ReadInt());
            clientCookie.SetSecure(@in.ReadBoolean());
        }
Ejemplo n.º 30
0
 /// <exception cref="System.InvalidCastException"/>
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.TypeLoadException"/>
 public override void LoadClassifier(ObjectInputStream ois, Properties props)
 {
     // can't have right types in deserialization
     base.LoadClassifier(ois, props);
     nodeFeatureIndicesMap = (IIndex <int>)ois.ReadObject();
     edgeFeatureIndicesMap = (IIndex <int>)ois.ReadObject();
     if (flags.secondOrderNonLinear)
     {
         inputLayerWeights4Edge  = (double[][])ois.ReadObject();
         outputLayerWeights4Edge = (double[][])ois.ReadObject();
     }
     else
     {
         linearWeights = (double[][])ois.ReadObject();
     }
     inputLayerWeights  = (double[][])ois.ReadObject();
     outputLayerWeights = (double[][])ois.ReadObject();
 }