Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        // package-private for testing
        Module deserialize(string sourcePath)
        {
#if NEVER
            string            cachePath = getCachePath(sourcePath);
            FileInputStream   fis       = null;
            ObjectInputStream ois       = null;
            try {
                fis = new FileInputStream(cachePath);
                ois = new ObjectInputStream(fis);
                return((Module)ois.readObject());
            } catch (Exception e) {
                return(null);
            } finally {
                try {
                    if (ois != null)
                    {
                        ois.close();
                    }
                    else if (fis != null)
                    {
                        fis.close();
                    }
                } catch (Exception e) {
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads and return s neural network instance from specified file
        /// </summary>
        /// <param name="file"> neural network file </param>
        /// <returns> neural network instance </returns>
        public static NeuralNetwork createFromFile(File file)
        {
            ObjectInputStream oistream = null;

            try {
                if (!file.exists())
                {
                    throw new FileNotFoundException("Cannot find file: " + file);
                }

                oistream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
                NeuralNetwork nnet = (NeuralNetwork)oistream.readObject();
                return(nnet);
            } catch (IOException ioe) {
                throw new NeurophException("Could not read neural network file!", ioe);
            } catch (ClassNotFoundException cnfe) {
                throw new NeurophException("Class not found while trying to read neural network from file!", cnfe);
            } finally {
                if (oistream != null)
                {
                    try {
                        oistream.close();
                    } catch (IOException) {
                    }
                }
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected org.maltparser.ml.lib.FeatureMap loadFeatureMap(java.io.InputStream is) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual FeatureMap loadFeatureMap(Stream @is)
        {
            FeatureMap map = new FeatureMap();

            try
            {
                ObjectInputStream input = new ObjectInputStream(@is);
                try
                {
                    map = (FeatureMap)input.readObject();
                }
                finally
                {
                    input.close();
                }
            }
            catch (ClassNotFoundException e)
            {
                throw new LibException("Load feature map error", e);
            }
            catch (IOException e)
            {
                throw new LibException("Load feature map error", e);
            }
            return(map);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object getConfigFileEntryObject(String fileName) throws org.maltparser.core.exception.MaltChainedException
        public virtual object getConfigFileEntryObject(string fileName)
        {
            object @object = null;

            try
            {
                ObjectInputStream input = new ObjectInputStream(getInputStreamFromConfigFileEntry(fileName));
                try
                {
                    @object = input.readObject();
                }
                catch (ClassNotFoundException e)
                {
                    throw new ConfigurationException("Could not load object '" + fileName + "' from mco-file", e);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Could not load object '" + fileName + "' from mco-file", e);
                }
                finally
                {
                    input.close();
                }
            }
            catch (IOException e)
            {
                throw new ConfigurationException("Could not load object from '" + fileName + "' in mco-file", e);
            }
            return(@object);
        }
Ejemplo n.º 6
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);
        }
    }
Ejemplo n.º 7
0
        public static ImmutableFst loadModel(InputStream inputStream)
        {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            ObjectInputStream   objectInputStream   = new ObjectInputStream(bufferedInputStream);
            ImmutableFst        result = ImmutableFst.readImmutableFst(objectInputStream);

            objectInputStream.close();
            bufferedInputStream.close();
            inputStream.close();
            return(result);
        }
Ejemplo n.º 8
0
 private static void close(ObjectInputStream @in)
 {
     if (@in != null)
     {
         try {
             @in.close();
         } catch (IOException e) {
             LOGGER.log(Level.WARNING, e.toString());
         }
     }
 }
Ejemplo n.º 9
0
        private static weka.classifiers.functions.MultilayerPerceptron loadModel(String name, java.io.File path)
        {
            // weka.classifiers.bayes.HMM .HMMEstimator.packageManagement.Package p=new ;
            weka.classifiers.functions.MultilayerPerceptron classifier;
            FileInputStream   fis = new FileInputStream(Constant.libsPath + "\\models\\" + "models" + name + ".model");
            ObjectInputStream ois = new ObjectInputStream(fis);

            classifier = (weka.classifiers.functions.MultilayerPerceptron)ois.readObject();
            ois.close();

            return(classifier);
        }
        private static weka.classifiers.functions.SMO loadSMOModel(String name, java.io.File path)
        {
            // weka.classifiers.bayes.HMM .HMMEstimator.packageManagement.Package p=new ;
            weka.classifiers.functions.SMO classifier;
            FileInputStream   fis = new FileInputStream(name);
            ObjectInputStream ois = new ObjectInputStream(fis);

            classifier = (weka.classifiers.functions.SMO)ois.readObject();
            ois.close();

            return(classifier);
        }
Ejemplo n.º 11
0
        private static weka.classifiers.meta.Bagging loadBaggingModel(String name, java.io.File path)
        {
            weka.classifiers.meta.Bagging classifier;

            FileInputStream   fis = new FileInputStream("..\\..\\..\\..\\libs\\models\\" + "models" + name + ".model");
            ObjectInputStream ois = new ObjectInputStream(fis);

            classifier = (weka.classifiers.meta.Bagging)ois.readObject();
            ois.close();

            return(classifier);
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Desktop.common.nomitech.common.db.project.ProjectTemplateTable projectTemplateFromSer(java.io.File paramFile) throws Exception
        public virtual ProjectTemplateTable projectTemplateFromSer(File paramFile)
        {
            FileStream           fileInputStream      = new FileStream(paramFile, FileMode.Open, FileAccess.Read);
            BufferedInputStream  bufferedInputStream  = new BufferedInputStream(fileInputStream);
            ObjectInputStream    objectInputStream    = new ObjectInputStream(bufferedInputStream);
            ProjectTemplateTable projectTemplateTable = null;

            try
            {
                projectTemplateTable = (ProjectTemplateTable)objectInputStream.readObject();
            }
            catch (Exception exception)
            {
                objectInputStream.close();
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
                throw exception;
            }
            objectInputStream.close();
            return(projectTemplateTable);
        }
Ejemplo n.º 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public Desktop.common.nomitech.common.base.BaseTableList resourcesFromSer(java.io.File paramFile) throws Exception
        public virtual BaseTableList resourcesFromSer(File paramFile)
        {
            FileStream          fileInputStream     = new FileStream(paramFile, FileMode.Open, FileAccess.Read);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
            ObjectInputStream   objectInputStream   = new ObjectInputStream(bufferedInputStream);
            BaseTableList       baseTableList       = null;

            try
            {
                baseTableList = (BaseTableList)objectInputStream.readObject();
            }
            catch (Exception exception)
            {
                objectInputStream.close();
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
                throw exception;
            }
            objectInputStream.close();
            return(baseTableList);
        }
Ejemplo n.º 14
0
        public static Fst loadModel(string filename)
        {
            long                timeInMillis        = Calendar.getInstance().getTimeInMillis();
            FileInputStream     fileInputStream     = new FileInputStream(filename);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
            ObjectInputStream   objectInputStream   = new ObjectInputStream(bufferedInputStream);
            Fst result = Fst.readFst(objectInputStream);

            objectInputStream.close();
            bufferedInputStream.close();
            fileInputStream.close();
            java.lang.System.err.println(new StringBuilder().append("Load Time: ").append((double)(Calendar.getInstance().getTimeInMillis() - timeInMillis) / 1000.0).toString());
            return(result);
        }
Ejemplo n.º 15
0
 public static object load(string fname)
 {
     object r = null;
     try
     {
         FileInputStream fs = new FileInputStream(fname);
         ObjectInputStream @in = new ObjectInputStream(fs);
         r = @in.readObject();
         @in.close();
         return r;
     }
     catch(Exception ex)
     {
         ex.printStackTrace();
     }
     return r;
 }
Ejemplo n.º 16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static MemberIsUnavailable deserialize(byte[] serialized) throws Exception
        private static MemberIsUnavailable Deserialize(sbyte[] serialized)
        {
            ObjectInputStream inputStream = null;

            try
            {
                MemoryStream byteArrayInputStream = new MemoryStream(serialized);
                inputStream = (new ObjectStreamFactory()).create(byteArrayInputStream);
                return(( MemberIsUnavailable )inputStream.readObject());
            }
            finally
            {
                if (inputStream != null)
                {
                    inputStream.close();
                }
            }
        }
Ejemplo n.º 17
0
        public static FaultSkin readFromFileSlow(String fileName)
        {
            throw new NotImplementedException();
#if false
            try
            {
                FileInputStream   fis  = new FileInputStream(fileName);
                ObjectInputStream ois  = new ObjectInputStream(fis);
                FaultSkin         skin = (FaultSkin)ois.readObject();
                ois.close();
                return(skin);
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
#endif
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Loads training set from the specified file
        /// </summary>
        /// <param name="filePath"> training set file </param>
        /// <returns> loded training set </returns>
        public static DataSet load(string filePath)
        {
            ObjectInputStream oistream = null;

            try
            {
                File file = new File(filePath);
                if (!file.exists())
                {
                    throw new FileNotFoundException("Cannot find file: " + filePath);
                }

                oistream = new ObjectInputStream(new FileInputStream(filePath));

                object  obj     = oistream.readObject();
                DataSet dataSet = (DataSet)obj;
                dataSet.FilePath = filePath;

                return(dataSet);
            }
            catch (IOException ioe)
            {
                throw new NeurophException("Error reading file!", ioe);
            }
            catch (ClassNotFoundException ex)
            {
                throw new NeurophException("Class not found while trying to read DataSet object from the stream!", ex);
            }
            finally
            {
                if (oistream != null)
                {
                    try
                    {
                        oistream.close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Loads neural network from the specified InputStream.
        /// </summary>
        /// <param name="inputStream"> input stream to load network from </param>
        /// <returns> loaded neural network as NeuralNetwork object </returns>
        public static NeuralNetwork load(InputStream inputStream)
        {
            ObjectInputStream oistream = null;

            try {
                oistream = new ObjectInputStream(new BufferedInputStream(inputStream));
                NeuralNetwork nnet = (NeuralNetwork)oistream.readObject();

                return(nnet);
            } catch (IOException ioe) {
                throw new NeurophException("Could not read neural network file!", ioe);
            } catch (ClassNotFoundException cnfe) {
                throw new NeurophException("Class not found while trying to read neural network from file!", cnfe);
            } finally {
                if (oistream != null)
                {
                    try {
                        oistream.close();
                    } catch (IOException) {
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public new static ImmutableFst loadModel(string filename)
        {
            ImmutableFst result;

            try
            {
                try
                {
                    try
                    {
                        FileInputStream     fileInputStream     = new FileInputStream(filename);
                        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                        ObjectInputStream   objectInputStream   = new ObjectInputStream(bufferedInputStream);
                        result = ImmutableFst.readImmutableFst(objectInputStream);
                        objectInputStream.close();
                        bufferedInputStream.close();
                        fileInputStream.close();
                    }
                    catch (FileNotFoundException ex)
                    {
                        Throwable.instancehelper_printStackTrace(ex);
                        return(null);
                    }
                }
                catch (IOException ex3)
                {
                    Throwable.instancehelper_printStackTrace(ex3);
                    return(null);
                }
            }
            catch (ClassNotFoundException ex5)
            {
                Throwable.instancehelper_printStackTrace(ex5);
                return(null);
            }
            return(result);
        }
Ejemplo n.º 21
0
        // package-private for testing
        Module deserialize(string sourcePath)
        {
#if NEVER
        string cachePath = getCachePath(sourcePath);
        FileInputStream fis = null;
        ObjectInputStream ois = null;
        try {
            fis = new FileInputStream(cachePath);
            ois = new ObjectInputStream(fis);
            return (Module) ois.readObject();
        } catch (Exception e) {
            return null;
        } finally {
            try {
                if (ois != null) {
                    ois.close();
                } else if (fis != null) {
                    fis.close();
                }
            } catch (Exception e) {

            }
        }
    }
Ejemplo n.º 22
0
    // Sign up on a given port. If registration is successful, the client will automatically log in for the user to begin playing.
    // Automatically called by connectToMainServer().
    public void signup(int port)
    {
        // Check if user left either field blank.
        if (usernameReg.text.Equals("") || passwordReg.text.Equals(""))
        {
            regFailedMessage.enabled = true;
            return;
        }

        // First, connect to the subserver at the given port.
        Socket cnxn        = null;
        bool   acctCreated = false;

        try {
            cnxn = new Socket(ip, port);
            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());

            // Send handshake
            output.writeInt(handshake);
            output.flush();

            // Now that we have connected and sent our handshake, we can send commands.
            // Here we will just sign up, close the connection, and log in using the given name and PW.

            output.writeInt(SIGNUP);
            output.flush();

            // Send username and PW.
            output.writeObject(usernameReg.text);
            output.flush();

            output.writeObject(passwordReg.text);
            output.flush();

            // Check if acc was created
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            cnxn.setSoTimeout(10000);
            acctCreated = input.readInt() == SPU.ServerResponse.ACCOUNT_CREATE_OK.ordinal();
            if (!acctCreated)
            {
                // Display an error message if registration failed.
                StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
                sms.RaiseErrorWindow("Account creation failed. That name may already be taken.");
            }

            // At this point, the user is (hopefully) signed up for the server on the given port. So, log in.
            // (Close connection and streams first!)
            output.close();
            input.close();
            cnxn.close();
            regFailedMessage.enabled = false;

            // If registration succeeded, at this point the client will auto-login and start playing the game.
            if (acctCreated)
            {
                usernameLogin.text = usernameReg.text;
                passwordLogin.text = passwordReg.text;
                ((StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)))).RegToLogin();
                loginAndPlay(port);
            }
        }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 subserver may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException) && !acctCreated)
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
            }
            else if (acctCreated)
            {
                sms.RaiseErrorWindow("Connection timed out, but registration was successful. The subserver may have gone down suddenly.");
            }
            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.StackTrace);
        }
    }
Ejemplo n.º 23
0
    // This method allows the user to log in and play (if login is successful). Automatically called by either connectToMainServer() or signup().
    public void loginAndPlay(int port)
    {
        // Check if user left either field blank.
        if (usernameLogin.text.Equals("") || passwordLogin.text.Equals(""))
        {
            loginErrorMessage.enabled = true;
            return;
        }

        // First, connect to the subserver at the given port.
        Socket cnxn         = null;
        bool   playerInGame = false;       // tracks whether the player is in-game (i.e. not in the main menu)

        try {
            cnxn = new Socket(ip, port);
            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());

            // Send handshake
            output.writeInt(handshake);
            output.flush();

            // Now that we have connected and sent our handshake, we can send commands.
            // First: log in.
            output.writeInt(LOGIN);
            output.flush();

            output.writeObject(usernameLogin.text);
            output.flush();

            output.writeObject(passwordLogin.text);
            output.flush();

            // Check if login was successful or failed
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            cnxn.setSoTimeout(10000);
            if (input.readInt() != SPU.ServerResponse.LOGIN_OK.ordinal())
            {
                // Login failed at this point. Disconnect from the server so the user can try again.
                loginErrorMessage.enabled = true;
                output.writeInt(DISCONNECT);
                output.flush();
                input.close();
                output.close();
                cnxn.close();
                return;
            }
            // At this point, login was successful.
            ((StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)))).saveLogin();
            loginErrorMessage.enabled = false;

            // Need to get the map first so the user can see stuff. First send the command, then receive the map and visibility.
            output.writeInt(GETCOND);
            output.flush();

            int          visibility = input.readInt();
            SPU.Tile[][] map        = (SPU.Tile[][])(input.readObject());

            // Load the game and start necessary threads.
            isLoading = true;
            StartCoroutine("LoadGame");
            while (isLoading)
            {
                ;
            }
            playerInGame = true;
            Destroy(GameObject.Find("Login Menu"));
            Destroy(GameObject.Find("Registration Menu"));
            Destroy(GameObject.Find("Main Menu Music"));

            // Create a thread to process user inputs (i.e. for the menu and for player movement)
            userInputThread = new System.Threading.Thread(new ThreadStart(new UserInputThread().ProcessInput));
            userInputThread.Start();
            while (!userInputThread.IsAlive)
            {
                ;                                         //loop until thread activates
            }
            // TO DO MUCH LATER: Draw the map, using visibility to determine visible tiles, and put this in the new scene.

            // At this point, process move commands one at a time (or logout if the user chooses).

            while (cmd != LOGOUT)
            {
                // First write the command...
                output.writeInt(cmd);
                output.flush();
                // ...then receive the updated visibility and map from the server.
                visibility = input.readInt();
                map        = (SPU.Tile[][])(input.readObject());
            }

            // At this point, user is ready to log out (cmd == LOGOUT).
            output.writeInt(LOGOUT);
            output.flush();

            // The game can just exit everything completely if the user is quitting to desktop.
            if (isQuitting)
            {
                Application.Quit();
            }

            input.close();
            output.close();
            cnxn.close();
            Destroy(GameObject.Find("BG Music"));
            isLoading = true;
            StartCoroutine("LoadMainMenu");
            while (isLoading)
            {
                ;
            }
            Destroy(this);
        }catch (java.lang.Exception e) {
            // Deal with a failed connection attempt
            StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
            if (cnxn == null)
            {
                sms.RaiseErrorWindow("Failed to connect. Check your connection settings. The subserver may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException) && !playerInGame)
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
            }
            else
            {
                // Return to the main menu, since connection has timed out.
                Destroy(startMenu);
                Destroy(GameObject.Find("BG Music"));
                userInputThread.Abort();
                userInputThread.Join();
                isLoading = true;
                StartCoroutine("LoadMainMenu");
                while (isLoading)
                {
                    ;
                }
                StartMenuScript sms2 = ((StartMenuScript)(GameObject.Find("Start Menu").GetComponent <StartMenuScript>()));
                sms2.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
                Destroy(this);
            }
        }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.StackTrace);
        }
    }