Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Contracts/3.3/StreamedObject.cs @ 4302

Last change on this file since 4302 was 4107, checked in by cneumuel, 14 years ago

migration from 3.2 to 3.3 completed. Hive Server and Client are now executable and as functional as they were in 3.2. (#1096)

File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using System.Runtime.Serialization.Formatters.Binary;
7using System.Runtime.Serialization;
8
9namespace HeuristicLab.Hive.Contracts {
10  [DataContract]
11  public class StreamedObject<T> : Stream {
12    private T encapsulatedObject;
13
14    private Stream stream =
15      new MemoryStream();
16
17    public StreamedObject(T encapsulatedObject) {
18      this.encapsulatedObject = encapsulatedObject;
19
20      BinaryFormatter formatter = new BinaryFormatter();
21      formatter.Serialize(this.stream, this.encapsulatedObject);
22
23      this.stream.Seek(0, SeekOrigin.Begin);
24    }
25
26    public T EncapsulatedObject {
27      get {
28        return this.encapsulatedObject;
29      }
30    }
31
32    public override bool CanRead {
33      get { return this.stream.CanRead; }
34    }
35
36    public override bool CanSeek {
37      get { throw new NotImplementedException(); }
38    }
39
40    public override bool CanWrite {
41      get { throw new NotImplementedException(); }
42    }
43
44    public override void Flush() {
45      throw new NotImplementedException();
46    }
47
48    public override long Length {
49      get { return this.stream.Length; }
50    }
51
52    public override long Position {
53      get {
54        return this.stream.Position;
55      }
56      set {
57        if(this.stream.Position != value)
58          throw new NotImplementedException();
59      }
60    }
61
62    public override int Read(byte[] buffer, int offset, int count) {
63      int read = this.stream.Read(buffer, offset, count);
64
65      return read;
66    }
67
68    public override long Seek(long offset, SeekOrigin origin) {
69      throw new NotImplementedException();
70    }
71
72    public override void SetLength(long value) {
73      throw new NotImplementedException();
74    }
75
76    public override void Write(byte[] buffer, int offset, int count) {
77      throw new NotImplementedException();
78    }
79
80    public override void Close() {
81      this.stream.Close();
82      base.Close();
83    }
84    protected override void Dispose(bool disposing) {
85      this.stream.Dispose();
86      base.Dispose(disposing);
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.