/// <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)); } } }
//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); }
//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(); } }
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()); } } }
//------------------------------------------------------------------------- /// <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); } }
/// <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) { } } } }
private void writeStringMap(ObjectOutputStream objectOutputStream, string[] array) { objectOutputStream.writeInt(array.Length); for (int i = 0; i < array.Length; i++) { objectOutputStream.writeObject(array[i]); } }
// 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); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private Payload payloadFor(Object value) throws java.io.IOException private Payload PayloadFor(object value) { MemoryStream bout = new MemoryStream(); ObjectOutputStream oout = new ObjectOutputStream(bout); oout.writeObject(value); oout.close(); sbyte[] bytes = bout.toByteArray(); return(new Payload(bytes, bytes.Length)); }
//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.defaultWriteObject(); MethodWrapper[] wrappers = new MethodWrapper[functions.Length]; for (int i = 0; i < wrappers.Length; i++) { wrappers[i] = new MethodWrapper(functions[i]); } @out.writeObject(wrappers); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public Payload broadcast(Object value) throws java.io.IOException public virtual Payload Broadcast(object value) { MemoryStream bout = new MemoryStream(); sbyte[] bytes; using (ObjectOutputStream oout = _objectOutputStreamFactory.create(bout)) { oout.writeObject(value); } bytes = bout.toByteArray(); return(new Payload(bytes, bytes.Length)); }
/// <summary> /// オブジェクトをシリアライズし,クリップボードに格納するための文字列を作成します /// </summary> /// <param name="obj">シリアライズするオブジェクト</param> /// <returns>シリアライズされた文字列</returns> private String getSerializedText(Object obj) { String str = ""; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); objectOutputStream.writeObject(obj); byte[] arr = outputStream.toByteArray(); str = CLIP_PREFIX + ":" + obj.GetType().FullName + ":" + Base64.encode(arr); return(str); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private byte[] writeObject(Object object) throws java.io.IOException private sbyte[] writeObject(object @object) { MemoryStream buffer = new MemoryStream(); ObjectOutputStream outputStream = new ObjectOutputStream(buffer); outputStream.writeObject(@object); outputStream.flush(); outputStream.close(); return(buffer.toByteArray()); }
//-------------------------------------------------------------------------------------------------- /// <summary> /// Serializes and deserializes an array using default serialization. /// </summary> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static MultiCurrencyAmountArray serializedDeserialize(MultiCurrencyAmountArray array) throws Exception private static MultiCurrencyAmountArray serializedDeserialize(MultiCurrencyAmountArray array) { MemoryStream byteOutputStream = new MemoryStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteOutputStream); objectOutputStream.writeObject(array); objectOutputStream.flush(); MemoryStream byteInputStream = new MemoryStream(byteOutputStream.toByteArray()); ObjectInputStream objectInputStream = new ObjectInputStream(byteInputStream); return((MultiCurrencyAmountArray)objectInputStream.readObject()); }
/// <summary> /// Serialize <seealso cref="#msgPatterns"/> and <seealso cref="#msgArguments"/>. /// </summary> /// <param name="out"> Stream. </param> /// <exception cref="IOException"> This should never happen. </exception> private void SerializeMessages(ObjectOutputStream @out) { // Step 1. //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int len = msgPatterns.size(); int len = msgPatterns.Count; @out.writeInt(len); // Step 2. for (int i = 0; i < len; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Localizable pat = msgPatterns.get(i); Localizable pat = msgPatterns[i]; // Step 3. @out.writeObject(pat); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Object[] args = msgArguments.get(i); object[] args = msgArguments[i]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int aLen = args.length; int aLen = args.Length; // Step 4. @out.writeInt(aLen); for (int j = 0; j < aLen; j++) { if (args[j] is Serializable) { // Step 5a. @out.writeObject(args[j]); } else { // Step 5b. @out.writeObject(NonSerializableReplacement(args[j])); } } } }
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(); } }
private void saveRobotToFile(Robot robot, File file) { deleteFileIfExists(file); try { using (ObjectOutputStream ous = new ObjectOutputStream(new BufferedOutputStream(new System.IO.FileStream(file, System.IO.FileMode.Create, System.IO.FileAccess.Write)))) { ous.writeObject(robot); } } catch (IOException ex) { throw new DAOException(ex); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void write(String inputFile, com.juliar.codegenerator.InstructionInvocation invocation) throws IOException public virtual void write(string inputFile, InstructionInvocation invocation) { string fileName = getLibiraryName(inputFile); try (OutputStream ostream = new FileOutputStream(fileName); ObjectOutputStream p = new ObjectOutputStream(ostream) ) { p.writeObject(invocation); p.flush(); } catch (IOException e) { JuliarLogger.log(e); } }
public void writeExternal(java.io.ObjectOutput __p1) { Page page = CurrentPage; ObjectStateFormatter osf = new ObjectStateFormatter(page); ObjectOutputStream outputStream = new ObjectOutputStream(__p1); if (page.NeedViewStateEncryption || page.EnableViewStateMac) { outputStream.writeObject(osf.Serialize(_state)); } else { osf.Serialize(outputStream, _state); } }
protected internal virtual void WriteFailureResponse(Exception exception, ChunkingChannelBuffer buffer) { try { MemoryStream bytes = new MemoryStream(); ObjectOutputStream @out = new ObjectOutputStream(bytes); @out.writeObject(exception); @out.close(); buffer.WriteBytes(bytes.toByteArray()); buffer.Done(); } catch (IOException) { _msgLog.warn("Couldn't send cause of error to client", exception); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected byte[] serializeToByteArray(Object deserializedObject) throws Exception protected internal override sbyte[] serializeToByteArray(object deserializedObject) { MemoryStream baos = new MemoryStream(); ObjectOutputStream ois = null; try { ois = new ObjectOutputStream(baos); ois.writeObject(deserializedObject); return(baos.toByteArray()); } finally { IoUtil.closeSilently(ois); IoUtil.closeSilently(baos); } }
public static void writeToFileSlow(String fileName, FaultSkin skin) { throw new NotImplementedException(); #if false try { FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(skin); oos.close(); } catch (Exception e) { throw new RuntimeException(e); } #endif }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static byte[] serialize(MemberIsUnavailable message) throws java.io.IOException private static sbyte[] Serialize(MemberIsUnavailable message) { ObjectOutputStream outputStream = null; try { MemoryStream byteArrayOutputStream = new MemoryStream(); outputStream = (new ObjectStreamFactory()).create(byteArrayOutputStream); outputStream.writeObject(message); return(byteArrayOutputStream.toByteArray()); } finally { if (outputStream != null) { outputStream.close(); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void saveFeatureMap(java.io.OutputStream os, org.maltparser.ml.lib.FeatureMap map) throws org.maltparser.core.exception.MaltChainedException protected internal virtual void saveFeatureMap(Stream os, FeatureMap map) { try { ObjectOutputStream output = new ObjectOutputStream(os); try { output.writeObject(map); } finally { output.close(); } } catch (IOException e) { throw new LibException("Save feature map error", e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void resourcesToSer(Desktop.common.nomitech.common.base.BaseTableList paramBaseTableList, java.io.File paramFile) throws Exception public virtual void resourcesToSer(BaseTableList paramBaseTableList, File paramFile) { FileStream fileOutputStream = new FileStream(paramFile, FileMode.Create, FileAccess.Write); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bufferedOutputStream); try { objectOutputStream.writeObject(paramBaseTableList); } catch (Exception exception) { objectOutputStream.close(); Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); throw exception; } objectOutputStream.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void worksheetTemplateToSer(Desktop.common.nomitech.common.db.project.WorksheetRevisionTable paramWorksheetRevisionTable, java.io.File paramFile) throws Exception public virtual void worksheetTemplateToSer(WorksheetRevisionTable paramWorksheetRevisionTable, File paramFile) { FileStream fileOutputStream = new FileStream(paramFile, FileMode.Create, FileAccess.Write); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); ObjectOutputStream objectOutputStream = new ObjectOutputStream(bufferedOutputStream); try { objectOutputStream.writeObject(paramWorksheetRevisionTable); } catch (Exception exception) { objectOutputStream.close(); Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); throw exception; } objectOutputStream.close(); }
/// <summary> /// Saves neural network into the specified file. /// </summary> /// <param name="filePath"> file path to save network into </param> public virtual void save(string filePath) { ObjectOutputStream @out = null; try { File file = new File(filePath); @out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); @out.writeObject(this); @out.flush(); } catch (IOException ioe) { throw new NeurophException("Could not write neural network to file!", ioe); } finally { if (@out != null) { try { @out.close(); } catch (IOException) { } } } }
private static void saveModel(Classifier c, String name, java.io.File fileName) { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream( new FileOutputStream("..\\..\\..\\..\\libs\\models\\" + "models" + name + ".model")); } catch (java.io.FileNotFoundException e1) { e1.printStackTrace(); } catch (java.io.IOException e1) { e1.printStackTrace(); } oos.writeObject(c); oos.flush(); oos.close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void trainExternal(String pathExternalTrain, java.util.LinkedHashMap<String, String> libOptions) throws org.maltparser.core.exception.MaltChainedException protected internal override void trainExternal(string pathExternalTrain, LinkedHashMap <string, string> libOptions) { try { binariesInstances2SVMFileFormat(getInstanceInputStreamReader(".ins"), getInstanceOutputStreamWriter(".ins.tmp")); Configuration config = Configuration; if (config.LoggerInfoEnabled) { config.logInfoMessage("Creating learner model (external) " + getFile(".mod").Name); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final libsvm.svm_problem prob = readProblem(getInstanceInputStreamReader(".ins"), libOptions); svm_problem prob = readProblem(getInstanceInputStreamReader(".ins"), libOptions); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String[] params = getLibParamStringArray(libOptions); string[] @params = getLibParamStringArray(libOptions); string[] arrayCommands = new string[@params.Length + 3]; int i = 0; arrayCommands[i++] = pathExternalTrain; for (; i <= @params.Length; i++) { arrayCommands[i] = @params[i - 1]; } arrayCommands[i++] = getFile(".ins.tmp").AbsolutePath; arrayCommands[i++] = getFile(".mod").AbsolutePath; if (verbosity == Verbostity.ALL) { config.logInfoMessage('\n'); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Process child = Runtime.getRuntime().exec(arrayCommands); Process child = Runtime.Runtime.exec(arrayCommands); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.InputStream in = child.getInputStream(); Stream @in = child.InputStream; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.InputStream err = child.getErrorStream(); Stream err = child.ErrorStream; int c; while ((c = @in.Read()) != -1) { if (verbosity == Verbostity.ALL) { config.logInfoMessage((char)c); } } while ((c = err.Read()) != -1) { if (verbosity == Verbostity.ALL || verbosity == Verbostity.ERROR) { config.logInfoMessage((char)c); } } if (child.waitFor() != 0) { config.logErrorMessage(" FAILED (" + child.exitValue() + ")"); } @in.Close(); err.Close(); svm_model model = svm.svm_load_model(getFile(".mod").AbsolutePath); MaltLibsvmModel xmodel = new MaltLibsvmModel(model, prob); ObjectOutputStream output = new ObjectOutputStream(new BufferedOutputStream(new FileStream(getFile(".moo").AbsolutePath, FileMode.Create, FileAccess.Write))); try { output.writeObject(xmodel); } finally { output.close(); } bool saveInstanceFiles = ((bool?)Configuration.getOptionValue("lib", "save_instance_files")).Value; if (!saveInstanceFiles) { getFile(".ins").delete(); getFile(".mod").delete(); getFile(".ins.tmp").delete(); } if (config.LoggerInfoEnabled) { config.logInfoMessage('\n'); } } catch (InterruptedException e) { throw new LibException("Learner is interrupted. ", e); } catch (ArgumentException e) { throw new LibException("The learner was not able to redirect Standard Error stream. ", e); } catch (SecurityException e) { throw new LibException("The learner cannot remove the instance file. ", e); } catch (IOException e) { throw new LibException("The learner cannot save the model file '" + getFile(".mod").AbsolutePath + "'. ", e); } catch (OutOfMemoryException e) { throw new LibException("Out of memory. Please increase the Java heap size (-Xmx<size>). ", e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void trainInternal(java.util.LinkedHashMap<String, String> libOptions) throws org.maltparser.core.exception.MaltChainedException protected internal override void trainInternal(LinkedHashMap <string, string> libOptions) { try { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final libsvm.svm_problem prob = readProblem(getInstanceInputStreamReader(".ins"), libOptions); svm_problem prob = readProblem(getInstanceInputStreamReader(".ins"), libOptions); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final libsvm.svm_parameter param = getLibSvmParameters(libOptions); svm_parameter param = getLibSvmParameters(libOptions); if (svm.svm_check_parameter(prob, param) != null) { throw new LibException(svm.svm_check_parameter(prob, param)); } Configuration config = Configuration; if (config.LoggerInfoEnabled) { config.logInfoMessage("Creating LIBSVM model " + getFile(".moo").Name + "\n"); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.PrintStream out = System.out; PrintStream @out = System.out; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.io.PrintStream err = System.err; PrintStream err = System.err; System.Out = NoPrintStream.NO_PRINTSTREAM; System.Err = NoPrintStream.NO_PRINTSTREAM; svm_model model = svm.svm_train(prob, param); System.Out = err; System.Out = @out; ObjectOutputStream output = new ObjectOutputStream(new BufferedOutputStream(new FileStream(getFile(".moo").AbsolutePath, FileMode.Create, FileAccess.Write))); try { output.writeObject(new MaltLibsvmModel(model, prob)); } finally { output.close(); } bool saveInstanceFiles = ((bool?)Configuration.getOptionValue("lib", "save_instance_files")).Value; if (!saveInstanceFiles) { getFile(".ins").delete(); } } catch (OutOfMemoryException e) { throw new LibException("Out of memory. Please increase the Java heap size (-Xmx<size>). ", e); } catch (ArgumentException e) { throw new LibException("The LIBSVM learner was not able to redirect Standard Error stream. ", e); } catch (SecurityException e) { throw new LibException("The LIBSVM learner cannot remove the instance file. ", e); } catch (IOException e) { throw new LibException("The LIBSVM learner cannot save the model file '" + getFile(".mod").AbsolutePath + "'. ", e); } }
/// <summary> /// Serialize this object to the given stream. /// </summary> /// <param name="out"> Stream. </param> /// <exception cref="IOException"> This should never happen. </exception> private void WriteObject(ObjectOutputStream @out) { @out.writeObject(throwable); SerializeMessages(@out); SerializeContext(@out); }