/// <summary>
        /// Serializes this <code>DragSourceContext</code>. This method first
        /// performs default serialization. Next, this object's
        /// <code>Transferable</code> is written out if and only if it can be
        /// serialized. If not, <code>null</code> is written instead. In this case,
        /// a <code>DragSourceContext</code> created from the resulting deserialized
        /// stream will contain a dummy <code>Transferable</code> which supports no
        /// <code>DataFlavor</code>s. Finally, this object's
        /// <code>DragSourceListener</code> is written out if and only if it can be
        /// serialized. If not, <code>null</code> is written instead.
        ///
        /// @serialData The default serializable fields, in alphabetical order,
        ///             followed by either a <code>Transferable</code> instance, or
        ///             <code>null</code>, followed by either a
        ///             <code>DragSourceListener</code> instance, or
        ///             <code>null</code>.
        /// @since 1.4
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
        private void WriteObject(ObjectOutputStream s)
        {
            s.DefaultWriteObject();

            s.WriteObject(SerializationTester.Test(Transferable_Renamed) ? Transferable_Renamed : null);
            s.WriteObject(SerializationTester.Test(Listener) ? Listener : null);
        }
示例#2
0
        /// <summary>
        /// Serialize <seealso cref="#context"/>.
        /// </summary>
        /// <param name="out"> Stream. </param>
        /// <exception cref="IOException"> This should never happen. </exception>
        private void SerializeContext(ObjectOutputStream @out)
        {
            // Step 1.
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int len = context.size();
            int len = context.Count;

            @out.writeInt(len);
            foreach (KeyValuePair <string, object> entry in context.SetOfKeyValuePairs())
            {
                // Step 2.
                @out.writeObject(entry.Key);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Object value = entry.getValue();
                object value = entry.Value;
                if (value is Serializable)
                {
                    // Step 3a.
                    @out.writeObject(value);
                }
                else
                {
                    // Step 3b.
                    @out.writeObject(NonSerializableReplacement(value));
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        private void WriteObject(ObjectOutputStream stream)
        {
            //    log.info("\nBefore compression:");
            //    log.info("arg size: " + argCounter.size() + "  total: " + argCounter.totalCount());
            //    log.info("stop size: " + stopCounter.size() + "  total: " + stopCounter.totalCount());
            ClassicCounter <IntDependency> fullArgCounter = argCounter;

            argCounter = new ClassicCounter <IntDependency>();
            foreach (IntDependency dependency in fullArgCounter.KeySet())
            {
                if (dependency.head != wildTW && dependency.arg != wildTW && dependency.head.word != -1 && dependency.arg.word != -1)
                {
                    argCounter.IncrementCount(dependency, fullArgCounter.GetCount(dependency));
                }
            }
            ClassicCounter <IntDependency> fullStopCounter = stopCounter;

            stopCounter = new ClassicCounter <IntDependency>();
            foreach (IntDependency dependency_1 in fullStopCounter.KeySet())
            {
                if (dependency_1.head.word != -1)
                {
                    stopCounter.IncrementCount(dependency_1, fullStopCounter.GetCount(dependency_1));
                }
            }
            //    log.info("After compression:");
            //    log.info("arg size: " + argCounter.size() + "  total: " + argCounter.totalCount());
            //    log.info("stop size: " + stopCounter.size() + "  total: " + stopCounter.totalCount());
            stream.DefaultWriteObject();
            argCounter  = fullArgCounter;
            stopCounter = fullStopCounter;
        }
示例#4
0
        /// <summary>
        /// Saves this training set to file specified in its filePath field
        /// </summary>
        public virtual void save()
        {
            ObjectOutputStream @out = null;

            try
            {
                File file = new File(this.filePath);
                @out = new ObjectOutputStream(new FileOutputStream(file));
                @out.writeObject(this);
                @out.flush();
            }
            catch (IOException ioe)
            {
                throw new NeurophException(ioe);
            }
            finally
            {
                if (@out != null)
                {
                    try
                    {
                        @out.close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static Object deepCopy(Object paramObject) throws Exception
        public static object deepCopy(object paramObject)
        {
            objectOutputStream = null;
            objectInputStream  = null;
            try
            {
                MemoryStream byteArrayOutputStream = new MemoryStream();
                objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
                objectOutputStream.writeObject(paramObject);
                objectOutputStream.flush();
                MemoryStream byteArrayInputStream = new MemoryStream(byteArrayOutputStream.toByteArray());
                objectInputStream = new ObjectInputStream(byteArrayInputStream);
                return(objectInputStream.readObject());
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception in ObjectCloner = " + exception);
                throw exception;
            }
            finally
            {
                objectOutputStream.close();
                objectInputStream.close();
            }
        }
示例#6
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private static void DemonstrateSerializationColumnDataClassifier()
        {
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Demonstrating working with a serialized classifier using serializeTo");
            ColumnDataClassifier cdc = new ColumnDataClassifier(where + "examples/cheese2007.prop");

            cdc.TrainClassifier(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);

            cdc.SerializeClassifier(oos);
            oos.Close();
            byte[] @object            = baos.ToByteArray();
            ByteArrayInputStream bais = new ByteArrayInputStream(@object);
            ObjectInputStream    ois  = new ObjectInputStream(bais);
            ColumnDataClassifier cdc2 = ColumnDataClassifier.GetClassifier(ois);

            ois.Close();
            // We compare the output of the deserialized classifier cdc2 versus the original one cl
            // For both we use a ColumnDataClassifier to convert text lines to examples
            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, cdc.ClassOf(d), cdc.ScoresOf(d).GetCount(cdc.ClassOf(d)));
                System.Console.Out.Printf("%s  =deser=>  %s (%.4f)%n", line, cdc2.ClassOf(d2), cdc2.ScoresOf(d).GetCount(cdc2.ClassOf(d)));
            }
        }
示例#7
0
        public void put(string key, ISerializable value, int saveTime)
        {
            using var baos = new System.IO.MemoryStream();

            try
            {
                using var oos = new ObjectOutputStream(baos);

                oos.WriteObject((Java.Lang.Object)value);

                byte[] data = baos.ToArray();

                if (saveTime != -1)
                {
                    put(key, data, saveTime);
                }
                else
                {
                    put(key, data);
                }
            }
            catch (System.Exception ex)
            {
                VPNLog.d("ACache", ex.ToString());
            }
        }
示例#8
0
        /// <summary>
        /// Writes default serializable fields to stream.  Writes
        /// a list of serializable <code>ItemListeners</code>
        /// as optional data.  The non-serializable
        /// <code>ItemListeners</code> are detected and
        /// no attempt is made to serialize them.
        /// </summary>
        /// <param name="s"> the <code>ObjectOutputStream</code> to write
        /// @serialData <code>null</code> terminated sequence of
        ///  0 or more pairs; the pair consists of a <code>String</code>
        ///  and an <code>Object</code>; the <code>String</code> indicates
        ///  the type of object and is one of the following:
        ///  <code>itemListenerK</code> indicating an
        ///    <code>ItemListener</code> object
        /// </param>
        /// <seealso cref= AWTEventMulticaster#save(ObjectOutputStream, String, EventListener) </seealso>
        /// <seealso cref= java.awt.Component#itemListenerK </seealso>
        /// <seealso cref= #readObject(ObjectInputStream) </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
        private void WriteObject(ObjectOutputStream s)
        {
            s.DefaultWriteObject();

            AWTEventMulticaster.Save(s, ItemListenerK, ItemListener);
            s.WriteObject(null);
        }
示例#9
0
        /// <summary>
        /// @serialData Default fields, followed by a two byte version number
        /// (major byte, followed by minor byte), followed by information on
        /// the log record parameter array.  If there is no parameter array,
        /// then -1 is written.  If there is a parameter array (possible of zero
        /// length) then the array length is written as an integer, followed
        /// by String values for each parameter.  If a parameter is null, then
        /// a null String is written.  Otherwise the output of Object.toString()
        /// is written.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(ObjectOutputStream out) throws IOException
        private void WriteObject(ObjectOutputStream @out)
        {
            // We have to call defaultWriteObject first.
            @out.DefaultWriteObject();

            // Write our version number.
            @out.WriteByte(1);
            @out.WriteByte(0);
            if (Parameters_Renamed == null)
            {
                @out.WriteInt(-1);
                return;
            }
            @out.WriteInt(Parameters_Renamed.Length);
            // Write string values for the parameters.
            for (int i = 0; i < Parameters_Renamed.Length; i++)
            {
                if (Parameters_Renamed[i] == null)
                {
                    @out.WriteObject(null);
                }
                else
                {
                    @out.WriteObject(Parameters_Renamed[i].ToString());
                }
            }
        }
示例#10
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Asserts that the object can be serialized and deserialized to an equal form.
 /// </summary>
 /// <param name="base">  the object to be tested </param>
 public static void assertSerialization(object @base)
 {
     assertNotNull(@base);
     try
     {
         using (MemoryStream baos = new MemoryStream())
         {
             using (ObjectOutputStream oos = new ObjectOutputStream(baos))
             {
                 oos.writeObject(@base);
                 oos.close();
                 using (MemoryStream bais = new MemoryStream(baos.toByteArray()))
                 {
                     using (ObjectInputStream ois = new ObjectInputStream(bais))
                     {
                         assertEquals(ois.readObject(), @base);
                     }
                 }
             }
         }
     }
     catch (Exception ex) when(ex is IOException || ex is ClassNotFoundException)
     {
         throw new Exception(ex);
     }
 }
示例#11
0
        /// <summary>
        /// <code>writeObject</code> for custom serialization.
        ///
        /// <para>This method writes this object's serialized form for
        /// this class as follows:
        ///
        /// </para>
        /// <para>The <code>writeObject</code> method is invoked on
        /// <code>out</code> passing this object's unique identifier
        /// (a <seealso cref="java.rmi.server.UID UID"/> instance) as the argument.
        ///
        /// </para>
        /// <para>Next, the {@link
        /// java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
        /// getRefClass} method is invoked on the activator's
        /// <code>RemoteRef</code> instance to obtain its external ref
        /// type name.  Next, the <code>writeUTF</code> method is
        /// invoked on <code>out</code> with the value returned by
        /// <code>getRefClass</code>, and then the
        /// <code>writeExternal</code> method is invoked on the
        /// <code>RemoteRef</code> instance passing <code>out</code>
        /// as the argument.
        ///
        /// @serialData The serialized data for this class comprises a
        /// <code>java.rmi.server.UID</code> (written with
        /// <code>ObjectOutput.writeObject</code>) followed by the
        /// external ref type name of the activator's
        /// <code>RemoteRef</code> instance (a string written with
        /// <code>ObjectOutput.writeUTF</code>), followed by the
        /// external form of the <code>RemoteRef</code> instance as
        /// written by its <code>writeExternal</code> method.
        ///
        /// </para>
        /// <para>The external ref type name of the
        /// <code>RemoteRef</Code> instance is
        /// determined using the definitions of external ref type
        /// names specified in the {@link java.rmi.server.RemoteObject
        /// RemoteObject} <code>writeObject</code> method
        /// <b>serialData</b> specification.  Similarly, the data
        /// written by the <code>writeExternal</code> method and read
        /// by the <code>readExternal</code> method of
        /// <code>RemoteRef</code> implementation classes
        /// corresponding to each of the defined external ref type
        /// names is specified in the {@link
        /// java.rmi.server.RemoteObject RemoteObject}
        /// <code>writeObject</code> method <b>serialData</b>
        /// specification.
        ///
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException, ClassNotFoundException
        private void WriteObject(ObjectOutputStream @out)
        {
            @out.WriteObject(Uid);

            RemoteRef @ref;

            if (Activator is RemoteObject)
            {
                @ref = ((RemoteObject)Activator).Ref;
            }
            else if (Proxy.isProxyClass(Activator.GetType()))
            {
                InvocationHandler handler = Proxy.getInvocationHandler(Activator);
                if (!(handler is RemoteObjectInvocationHandler))
                {
                    throw new InvalidObjectException("unexpected invocation handler");
                }
                @ref = ((RemoteObjectInvocationHandler)handler).Ref;
            }
            else
            {
                throw new InvalidObjectException("unexpected activator type");
            }
            @out.WriteUTF(@ref.GetRefClass(@out));
            @ref.WriteExternal(@out);
        }
示例#12
0
        /// <summary>
        /// writeObject is called to save the state of the {@code BatchUpdateException}
        /// to a stream.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException, ClassNotFoundException
        private void WriteObject(ObjectOutputStream s)
        {
            ObjectOutputStream.PutField fields = s.PutFields();
            fields.Put("updateCounts", UpdateCounts_Renamed);
            fields.Put("longUpdateCounts", LongUpdateCounts);
            s.WriteFields();
        }
示例#13
0
 public void handleStream()
 {
     try
     {
         setClient(serverSocket.accept());
         //reflush the stream
         outputStream = new ObjectOutputStream(getClient().getOutputStream());
         inputStream  = new ObjectInputStream(getClient().getInputStream());
     }
     catch (IOException e)
     {
         e.printStackTrace();
     }
     finally
     {
         try
         { //try to close gracefully
             getClient().close();
         }
         catch (IOException e)
         {
             e.printStackTrace();
         }
     }
 }
示例#14
0
 public void handleStream(Socket client)
 {
     try
     {
         setClient(client);
         //und dat naked fields ?
         outputStream = new ObjectOutputStream(getClient().getOutputStream());
         inputStream  = new ObjectInputStream(getClient().getInputStream());
     }
     catch (IOException e)
     {
         e.printStackTrace();
     }
     finally
     {
         try
         { //try to close gracefully
             client.close();
         }
         catch (IOException e)
         {
             e.printStackTrace();
         }
     }
 }
        /// <summary>
        /// @serialData Default field.
        /// </summary>

        /*
         * Writes the contents of the perms field out as a Hashtable
         * in which the values are Vectors for
         * serialization compatibility with earlier releases.
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
        private void WriteObject(ObjectOutputStream @out)
        {
            // Don't call out.defaultWriteObject()

            // Copy perms into a Hashtable
            Dictionary <String, Vector <UnresolvedPermission> > permissions = new Dictionary <String, Vector <UnresolvedPermission> >(Perms.Size() * 2);

            // Convert each entry (List) into a Vector
            lock (this)
            {
                Set <Map_Entry <String, List <UnresolvedPermission> > > set = Perms.EntrySet();
                foreach (Map_Entry <String, List <UnresolvedPermission> > e in set)
                {
                    // Convert list into Vector
                    List <UnresolvedPermission>   list = e.Value;
                    Vector <UnresolvedPermission> vec  = new Vector <UnresolvedPermission>(list.Count);
                    lock (list)
                    {
                        vec.AddAll(list);
                    }

                    // Add to Hashtable being serialized
                    permissions.Put(e.Key, vec);
                }
            }

            // Write out serializable fields
            ObjectOutputStream.PutField pfields = @out.PutFields();
            pfields.Put("permissions", permissions);
            @out.WriteFields();
        }
示例#16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException, ClassNotFoundException
            internal virtual void writeObject(ObjectOutputStream @out)
            {
                @out.defaultWriteObject();
                @out.writeObject(method.DeclaringClass);
                @out.writeObject(method.Name);
                @out.writeObject(method.ParameterTypes);
            }
示例#17
0
 /// <summary>Dump out the contents of the cache to the backing file.</summary>
 public virtual void Write()
 {
     // Do this even if not writing so we printStats() at good times
     entriesSinceLastWritten = 0;
     if (frequencyToWrite < CacheEntries / 4)
     {
         frequencyToWrite *= 2;
     }
     if (backingFile == null)
     {
         return;
     }
     try
     {
         using (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(backingFile)))
         {
             log.Info("Writing cache (size: " + Count + ") to " + backingFile);
             oos.WriteObject(this);
         }
     }
     catch (Exception ex)
     {
         log.Info("Error writing cache to file: " + backingFile + '!');
         log.Info(ex);
     }
 }
 // method for writing a ClassifierCombiner to an ObjectOutputStream
 public override void SerializeClassifier(ObjectOutputStream oos)
 {
     try
     {
         // record the properties used to initialize
         oos.WriteObject(initProps);
         // this is a bit of a hack, but have to write this twice so you can get it again
         // after you initialize AbstractSequenceClassifier
         // basically when this is read from the ObjectInputStream, I read it once to call
         // super(props) and then I read it again so I can set this.initProps
         // TODO: probably should have AbstractSequenceClassifier store initProps to get rid of this double writing
         oos.WriteObject(initProps);
         // record the initial loadPaths
         oos.WriteObject(initLoadPaths);
         // record the combinationMode
         string combinationModeString = combinationMode.ToString();
         oos.WriteObject(combinationModeString);
         // get the number of classifiers to write to disk
         int numClassifiers = baseClassifiers.Count;
         oos.WriteInt(numClassifiers);
         // go through baseClassifiers and write each one to disk with CRFClassifier's serialize method
         log.Info(string.Empty);
         foreach (AbstractSequenceClassifier <IN> asc in baseClassifiers)
         {
             //CRFClassifier crfc = (CRFClassifier) asc;
             //log.info("Serializing a base classifier...");
             asc.SerializeClassifier(oos);
         }
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(e);
     }
 }
        /// <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);
        }
示例#20
0
        private void writeFst(ObjectOutputStream objectOutputStream)
        {
            this.writeStringMap(objectOutputStream, this.isyms);
            this.writeStringMap(objectOutputStream, this.osyms);
            objectOutputStream.writeInt(this.states.indexOf(this.start));
            objectOutputStream.writeObject(this.semiring);
            objectOutputStream.writeInt(this.states.size());
            HashMap hashMap = new HashMap(this.states.size(), 1f);
            int     i;

            for (i = 0; i < this.states.size(); i++)
            {
                State state = (State)this.states.get(i);
                objectOutputStream.writeInt(state.getNumArcs());
                objectOutputStream.writeFloat(state.getFinalWeight());
                objectOutputStream.writeInt(state.getId());
                hashMap.put(state, Integer.valueOf(i));
            }
            i = this.states.size();
            for (int j = 0; j < i; j++)
            {
                State state2  = (State)this.states.get(j);
                int   numArcs = state2.getNumArcs();
                for (int k = 0; k < numArcs; k++)
                {
                    Arc arc = state2.getArc(k);
                    objectOutputStream.writeInt(arc.getIlabel());
                    objectOutputStream.writeInt(arc.getOlabel());
                    objectOutputStream.writeFloat(arc.getWeight());
                    objectOutputStream.writeInt(((Integer)hashMap.get(arc.getNextState())).intValue());
                }
            }
        }
示例#21
0
        /// <summary>
        /// Writes default serializable fields to stream.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
        private void WriteObject(ObjectOutputStream s)
        {
            // 4352819: We only need this degenerate writeObject to make
            // it safe for future versions of this class to write optional
            // data to the stream.
            s.DefaultWriteObject();
        }
        /// <exception cref="System.IO.IOException"/>
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                log.Info(usage);
                System.Environment.Exit(1);
            }
            Properties options    = StringUtils.ArgsToProperties(args, argOptionDefs);
            string     outputPath = options.GetProperty("o");

            if (outputPath == null)
            {
                throw new ArgumentException("-o argument (output path for built tagger) is required");
            }
            string[]     remainingArgs = options.GetProperty(string.Empty).Split(" ");
            IList <File> fileList      = new List <File>();

            foreach (string arg in remainingArgs)
            {
                fileList.Add(new File(arg));
            }
            Edu.Stanford.Nlp.International.Spanish.Pipeline.AnCoraPOSStats stats = new Edu.Stanford.Nlp.International.Spanish.Pipeline.AnCoraPOSStats(fileList, outputPath);
            stats.Process();
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(outputPath));
            TwoDimensionalCounter <string, string> tagger = stats.GetUnigramTagger();

            oos.WriteObject(tagger);
            System.Console.Out.Printf("Wrote tagger to %s%n", outputPath);
        }
示例#23
0
 /// <exception cref="System.IO.IOException"></exception>
 private void WriteObject(ObjectOutputStream os)
 {
     os.WriteInt(w1);
     os.WriteInt(w2);
     os.WriteInt(w3);
     os.WriteInt(w4);
     os.WriteInt(w5);
 }
示例#24
0
        /// <summary>
        /// Write out the default serializable data, after ensuring the
        /// <code>zoneStrings</code> field is initialized in order to make
        /// sure the backward compatibility.
        ///
        /// @since 1.6
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException
        private void WriteObject(ObjectOutputStream stream)
        {
            if (ZoneStrings_Renamed == null)
            {
                ZoneStrings_Renamed = TimeZoneNameUtility.getZoneStrings(Locale);
            }
            stream.DefaultWriteObject();
        }
示例#25
0
 private void writeStringMap(ObjectOutputStream objectOutputStream, string[] array)
 {
     objectOutputStream.writeInt(array.Length);
     for (int i = 0; i < array.Length; i++)
     {
         objectOutputStream.writeObject(array[i]);
     }
 }
示例#26
0
    // Connect to server address at port 1337 (main server) and get a new port on which to login or sign up.
    public void connectToMainServer(bool newAcct)
    {
        Socket cnxn = null;

        try {
            // 1st step: Connect to main server and send handshake.
            cnxn = new Socket(ip, 1337);

            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());
            output.writeInt(handshake);
            output.flush();

            // Must now send username.
            string username = newAcct ? usernameReg.text : usernameLogin.text;
            output.writeObject(username);
            output.flush();

            // Receive whatever port the server sends (random or determined).
            cnxn.setSoTimeout(10000);             // 10-sec timeout for input reads
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            int nextPort            = input.readInt();

            // Close streams and connection.
            input.close();
            output.close();
            cnxn.close();

            // We got a port now! At this point, either log in or sign up.
            if (newAcct)
            {
                signup(nextPort);
            }
            else
            {
                loginAndPlay(nextPort);
            }
        } catch (java.lang.Exception e) {
            // Display some kind of error window if there was a connection error (basically a Java exception).
            // If the socket is null, the connection attempt failed; otherwise, the connection timed out, or something else happened.
            StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
            if (cnxn == null)
            {
                sms.RaiseErrorWindow("Failed to connect. Check your connection settings. The main server may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException))
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The main server may have gone down.");
            }
            else
            {
                sms.RaiseErrorWindow("An unknown exception occurred when trying to connect to the main server.");
            }
        } catch (System.Exception e) {
            // This handles C# exceptions. These shouldn't happen, which is why the errors are printed to the console (for us to test for ourselves).
            print("Encountered a C# exception:\n");
            print(e.Message);
        }
    }
示例#27
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
        private void WriteObject(ObjectOutputStream @out)
        {
            // Don't call defaultWriteObject()
            ObjectOutputStream.PutField pfields = @out.PutFields();
            pfields.Put("hostname", Holder.Hostname);
            pfields.Put("addr", Holder.Addr);
            pfields.Put("port", Holder.Port_Renamed);
            @out.WriteFields();
        }
        /// <exception cref="System.IO.IOException"></exception>
        private void CreateBytes(ISerializable ser)
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream    @out = new ObjectOutputStream(baos);

            @out.WriteObject(ser);
            @out.Flush();
            this.objSer = baos.ToByteArray();
        }
示例#29
0
        /// <summary>
        /// Serializes this <code>DragSource</code>. This method first performs
        /// default serialization. Next, it writes out this object's
        /// <code>FlavorMap</code> if and only if it can be serialized. If not,
        /// <code>null</code> is written instead. Next, it writes out
        /// <code>Serializable</code> listeners registered with this
        /// object. Listeners are written in a <code>null</code>-terminated sequence
        /// of 0 or more pairs. The pair consists of a <code>String</code> and an
        /// <code>Object</code>; the <code>String</code> indicates the type of the
        /// <code>Object</code> and is one of the following:
        /// <ul>
        /// <li><code>dragSourceListenerK</code> indicating a
        ///     <code>DragSourceListener</code> object;
        /// <li><code>dragSourceMotionListenerK</code> indicating a
        ///     <code>DragSourceMotionListener</code> object.
        /// </ul>
        ///
        /// @serialData Either a <code>FlavorMap</code> instance, or
        ///      <code>null</code>, followed by a <code>null</code>-terminated
        ///      sequence of 0 or more pairs; the pair consists of a
        ///      <code>String</code> and an <code>Object</code>; the
        ///      <code>String</code> indicates the type of the <code>Object</code>
        ///      and is one of the following:
        ///      <ul>
        ///      <li><code>dragSourceListenerK</code> indicating a
        ///          <code>DragSourceListener</code> object;
        ///      <li><code>dragSourceMotionListenerK</code> indicating a
        ///          <code>DragSourceMotionListener</code> object.
        ///      </ul>.
        /// @since 1.4
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
        private void WriteObject(ObjectOutputStream s)
        {
            s.DefaultWriteObject();

            s.WriteObject(SerializationTester.Test(FlavorMap_Renamed) ? FlavorMap_Renamed : null);

            DnDEventMulticaster.Save(s, DragSourceListenerK, Listener);
            DnDEventMulticaster.Save(s, DragSourceMotionListenerK, MotionListener);
            s.WriteObject(null);
        }
 static SerializationTester()
 {
     try
     {
         Stream = new ObjectOutputStream(new OutputStreamAnonymousInnerClassHelper());
     }
     catch (IOException)
     {
     }
 }
 public static void save(string fname, object obj)
 {
     try
     {
         FileOutputStream fs = new FileOutputStream(fname);
         ObjectOutputStream @out = new ObjectOutputStream(fs);
         @out.writeObject(obj);
         @out.close();
     }
     catch(Exception ex)
     {
         ex.printStackTrace();
     }
 }
示例#32
0
		/**
		 * Ensure object is fully parsed before invoking java serialization.  The backing byte array
		 * is transient so if the object has parseLazy = true and hasn't invoked checkParse yet
		 * then data will be lost during serialization.
		 */
		private void writeObject(ObjectOutputStream out) throws IOException {