diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 35e795b..8ba6643 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -37,6 +37,8 @@ using System.Text; | |||
37 | using libsecondlife; | 37 | using libsecondlife; |
38 | using Nini.Config; | 38 | using Nini.Config; |
39 | 39 | ||
40 | using System.Runtime.Serialization; | ||
41 | using System.Runtime.Serialization.Formatters.Binary; | ||
40 | namespace OpenSim.Framework | 42 | namespace OpenSim.Framework |
41 | { | 43 | { |
42 | public class Util | 44 | public class Util |
@@ -509,7 +511,63 @@ namespace OpenSim.Framework | |||
509 | { | 511 | { |
510 | return ""; | 512 | return ""; |
511 | } | 513 | } |
514 | } | ||
515 | |||
516 | public static void SerializeToFile(string filename, Object obj) | ||
517 | { | ||
518 | IFormatter formatter = new BinaryFormatter(); | ||
519 | Stream stream = null; | ||
520 | |||
521 | try | ||
522 | { | ||
523 | stream = new FileStream( | ||
524 | filename, FileMode.Create, | ||
525 | FileAccess.Write, FileShare.None); | ||
526 | |||
527 | formatter.Serialize(stream, obj); | ||
528 | } | ||
529 | catch (Exception e) | ||
530 | { | ||
531 | System.Console.WriteLine(e.Message); | ||
532 | System.Console.WriteLine(e.StackTrace); | ||
533 | } | ||
534 | finally | ||
535 | { | ||
536 | if (stream != null) | ||
537 | { | ||
538 | stream.Close(); | ||
539 | } | ||
540 | } | ||
541 | } | ||
542 | |||
543 | public static Object DeserializeFromFile(string filename) | ||
544 | { | ||
545 | IFormatter formatter = new BinaryFormatter(); | ||
546 | Stream stream = null; | ||
547 | Object ret = null; | ||
548 | |||
549 | try | ||
550 | { | ||
551 | stream = new FileStream( | ||
552 | filename, FileMode.Open, | ||
553 | FileAccess.Read, FileShare.None); | ||
554 | |||
555 | ret = formatter.Deserialize(stream); | ||
556 | } | ||
557 | catch (Exception e) | ||
558 | { | ||
559 | System.Console.WriteLine(e.Message); | ||
560 | System.Console.WriteLine(e.StackTrace); | ||
561 | } | ||
562 | finally | ||
563 | { | ||
564 | if (stream != null) | ||
565 | { | ||
566 | stream.Close(); | ||
567 | } | ||
568 | } | ||
512 | 569 | ||
570 | return ret; | ||
513 | } | 571 | } |
514 | } | 572 | } |
515 | } | 573 | } |