// 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); } }
/// <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()); } } }
/// <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); }
/// <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); }
/// <exception cref="System.IO.IOException"/> public virtual void Save(string path) { // save the CRF this.classifier.SerializeClassifier(path); // save the additional arguments FileOutputStream fos = new FileOutputStream(path + ".extra"); ObjectOutputStream @out = new ObjectOutputStream(fos); @out.WriteObject(this.gazetteerLocation); @out.WriteObject(this.annotationsToSkip); @out.WriteObject(this.useSubTypes); @out.WriteObject(this.useBIO); @out.Close(); }
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(); }
/// <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); }
/// <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); }
internal static bool Test(Object obj) { if (!(obj is Serializable)) { return(false); } try { Stream.WriteObject(obj); } catch (IOException) { return(false); } finally { // Fix for 4503661. // Reset the stream so that it doesn't keep a reference to the // written object. try { Stream.Reset(); } catch (IOException) { // Ignore the exception. } } return(true); }
/// <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))); } }
/// <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); }
/// <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); } }
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()); } }
/// <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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected static void save(java.io.ObjectOutputStream s, String k, java.util.EventListener l) throws java.io.IOException protected internal static void Save(ObjectOutputStream s, String k, EventListener l) { if (l == null) { return; } else if (l is AWTEventMulticaster) { ((AWTEventMulticaster)l).SaveInternal(s, k); } else if (l is Serializable) { s.WriteObject(k); s.WriteObject(l); } }
/// <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(); }
/// <summary> /// @serialData Null terminated list of <code>PropertyChangeListeners</code>. /// <para> /// At serialization time we skip non-serializable listeners and /// only serialize the serializable listeners. /// </para> /// </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) { Dictionary <String, PropertyChangeSupport> children = null; PropertyChangeListener[] listeners = null; lock (this.Map) { foreach (Map_Entry <String, PropertyChangeListener[]> entry in this.Map.Entries) { String property = entry.Key; if (property == null) { listeners = entry.Value; } else { if (children == null) { children = new Dictionary <>(); } PropertyChangeSupport pcs = new PropertyChangeSupport(this.Source); pcs.Map.Set(null, entry.Value); children[property] = pcs; } } } ObjectOutputStream.PutField fields = s.PutFields(); fields.Put("children", children); fields.Put("source", this.Source); fields.Put("propertyChangeSupportSerializedDataVersion", 2); s.WriteFields(); if (listeners != null) { foreach (PropertyChangeListener l in listeners) { if (l is Serializable) { s.WriteObject(l); } } } s.WriteObject(null); }
/// <summary> /// Serialize this Object in a manner which is binary-compatible with the /// JDK. /// </summary> /// <exception cref="System.IO.IOException"/> private void WriteObject(ObjectOutputStream s) { IEnumerator <E> it = GetEnumerator(); s.WriteInt(Count * 2); // expectedMaxSize s.WriteInt(Count); while (it.MoveNext()) { s.WriteObject(it.Current); } }
/// <exception cref="System.IO.IOException"/> private void Save(string path) { System.Console.Out.Write("Saving classifier to " + path + "... "); // make sure the directory specified by path exists int lastSlash = path.LastIndexOf(File.separator); if (lastSlash > 0) { File dir = new File(Sharpen.Runtime.Substring(path, 0, lastSlash)); if (!dir.Exists()) { dir.Mkdirs(); } } ObjectOutputStream @out = new ObjectOutputStream(new FileOutputStream(path)); @out.WriteObject(weights); @out.WriteObject(featureIndex); @out.WriteObject(labelIndex); @out.Close(); System.Console.Out.WriteLine("done."); }
/* * public void addPatterns(String id, Map<Integer, Set<Integer>> p, PreparedStatement pstmt) throws IOException, SQLException { * for (Map.Entry<Integer, Set<Integer>> en2 : p.entrySet()) { * addPattern(id, en2.getKey(), en2.getValue(), pstmt); * if(useDBForTokenPatterns) * pstmt.addBatch(); * } * } */ /* * public void addPatterns(String sentId, int tokenId, Set<Integer> patterns) throws SQLException, IOException{ * PreparedStatement pstmt = null; * Connection conn= null; * if(useDBForTokenPatterns) { * conn = SQLConnection.getConnection(); * pstmt = getPreparedStmt(conn); * } * * addPattern(sentId, tokenId, patterns, pstmt); * * if(useDBForTokenPatterns){ * pstmt.execute(); * conn.commit(); * pstmt.close(); * conn.close(); * } * } */ /* * private void addPattern(String sentId, int tokenId, Set<Integer> patterns, PreparedStatement pstmt) throws SQLException, IOException { * * if(pstmt != null){ * // ByteArrayOutputStream baos = new ByteArrayOutputStream(); * // ObjectOutputStream oos = new ObjectOutputStream(baos); * // oos.writeObject(patterns); * // byte[] patsAsBytes = baos.toByteArray(); * // ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); * // pstmt.setBinaryStream(1, bais, patsAsBytes.length); * // pstmt.setObject(2, sentId); * // pstmt.setInt(3, tokenId); * // pstmt.setString(4,sentId); * // pstmt.setInt(5, tokenId); * // ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); * // ObjectOutputStream oos2 = new ObjectOutputStream(baos2); * // oos2.writeObject(patterns); * // byte[] patsAsBytes2 = baos2.toByteArray(); * // ByteArrayInputStream bais2 = new ByteArrayInputStream(patsAsBytes2); * // pstmt.setBinaryStream(6, bais2, patsAsBytes2.length); * // pstmt.setString(7,sentId); * // pstmt.setInt(8, tokenId); * * ByteArrayOutputStream baos = new ByteArrayOutputStream(); * ObjectOutputStream oos = new ObjectOutputStream(baos); * oos.writeObject(patterns); * byte[] patsAsBytes = baos.toByteArray(); * ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); * pstmt.setBinaryStream(3, bais, patsAsBytes.length); * pstmt.setObject(1, sentId); * pstmt.setInt(2, tokenId); * * * } else{ * if(!patternsForEachToken.containsKey(sentId)) * patternsForEachToken.put(sentId, new ConcurrentHashMap<Integer, Set<Integer>>()); * patternsForEachToken.get(sentId).put(tokenId, patterns); * } * }*/ /// <exception cref="Java.Sql.SQLException"/> /// <exception cref="System.IO.IOException"/> private void AddPattern(string sentId, IDictionary <int, ICollection <E> > patterns, IPreparedStatement pstmt) { if (pstmt != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.WriteObject(patterns); byte[] patsAsBytes = baos.ToByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); pstmt.SetBinaryStream(2, bais, patsAsBytes.Length); pstmt.SetObject(1, sentId); } }
/* Serialization support. */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void saveInternal(java.io.ObjectOutputStream s, String k) throws java.io.IOException protected internal virtual void SaveInternal(ObjectOutputStream s, String k) { if (a is AWTEventMulticaster) { ((AWTEventMulticaster)a).SaveInternal(s, k); } else if (a is Serializable) { s.WriteObject(k); s.WriteObject(a); } if (b is AWTEventMulticaster) { ((AWTEventMulticaster)b).SaveInternal(s, k); } else if (b is Serializable) { s.WriteObject(k); s.WriteObject(b); } }
private byte[] GetBytes(IDictionary <int, ICollection <E> > p) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.WriteObject(p); return(baos.ToByteArray()); } catch (IOException e) { throw new Exception(e); } }
/// <exception cref="System.IO.IOException"></exception> public override void WriteTo(OutputStream outstream) { Args.NotNull(outstream, "Output stream"); if (this.objSer == null) { ObjectOutputStream @out = new ObjectOutputStream(outstream); @out.WriteObject(this.objRef); @out.Flush(); } else { outstream.Write(this.objSer); outstream.Flush(); } }
internal static void SaveSegmenterDataToSerialized(Edu.Stanford.Nlp.Parser.Lexparser.ChineseLexiconAndWordSegmenter cs, string filename) { try { log.Info("Writing segmenter in serialized format to file " + filename + " "); ObjectOutputStream @out = IOUtils.WriteStreamFromString(filename); @out.WriteObject(cs); @out.Close(); log.Info("done."); } catch (IOException ioe) { Sharpen.Runtime.PrintStackTrace(ioe); } }
/// <summary>Saves the singleton predictor model to the given filename.</summary> /// <remarks> /// Saves the singleton predictor model to the given filename. /// If there is an error, a RuntimeIOException is thrown. /// </remarks> private static void SaveToSerialized(LogisticClassifier <string, string> predictor, string filename) { try { log.Info("Writing singleton predictor in serialized format to file " + filename + ' '); ObjectOutputStream @out = IOUtils.WriteStreamFromString(filename); @out.WriteObject(predictor); @out.Close(); log.Info("done."); } catch (IOException ioe) { throw new RuntimeIOException(ioe); } }
public virtual byte[] ConvertToBytes(IList <Tree> input) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(gos); IList <Tree> transformed = CollectionUtils.TransformAsList(input, treeBasicCategories); IList <Tree> filtered = CollectionUtils.FilterAsList(transformed, treeFilter); oos.WriteObject(filtered.Count); foreach (Tree tree in filtered) { oos.WriteObject(tree.ToString()); } oos.Close(); gos.Close(); bos.Close(); return(bos.ToByteArray()); } catch (IOException e) { throw new RuntimeIOException(e); } }
/// <summary>Returns the result of applying the parser to arg as a serialized tree.</summary> /// <exception cref="System.IO.IOException"/> public virtual void HandleTree(string arg, OutputStream outStream) { Tree tree = Parse(arg, false); if (tree == null) { return; } log.Info(tree); if (tree != null) { ObjectOutputStream oos = new ObjectOutputStream(outStream); oos.WriteObject(tree); oos.Flush(); } }
/// <summary> /// Constructs a SignedObject from any Serializable object. /// The given object is signed with the given signing key, using the /// designated signature engine. /// </summary> /// <param name="object"> the object to be signed. </param> /// <param name="signingKey"> the private key for signing. </param> /// <param name="signingEngine"> the signature signing engine. /// </param> /// <exception cref="IOException"> if an error occurs during serialization </exception> /// <exception cref="InvalidKeyException"> if the key is invalid. </exception> /// <exception cref="SignatureException"> if signing fails. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public SignedObject(Serializable object, PrivateKey signingKey, Signature signingEngine) throws IOException, InvalidKeyException, SignatureException public SignedObject(Serializable @object, PrivateKey signingKey, Signature signingEngine) { // creating a stream pipe-line, from a to b ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutput a = new ObjectOutputStream(b); // write and flush the object content to byte array a.WriteObject(@object); a.Flush(); a.Close(); this.Content = b.ToByteArray(); b.Close(); // now sign the encapsulated object this.Sign(signingKey, signingEngine); }
/// <exception cref="System.IO.IOException"></exception> private void WriteObject(ObjectOutputStream @out) { @out.WriteObject(cookie.GetName()); @out.WriteObject(cookie.GetValue()); @out.WriteObject(cookie.GetComment()); @out.WriteObject(cookie.GetDomain()); @out.WriteObject(cookie.GetExpiryDate()); @out.WriteObject(cookie.GetPath()); @out.WriteInt(cookie.GetVersion()); @out.WriteBoolean(cookie.IsSecure()); }
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); } }