Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.Hive.Contracts/3.2/StreamedObject.cs @ 2498

Last change on this file since 2498 was 1939, checked in by svonolfe, 16 years ago

Large amounts of data are now transferred streamed (fixed ticket #660)

File size: 2.1 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 =
21        new BinaryFormatter();
22      formatter.Serialize(this.stream, this.encapsulatedObject);
23
24      this.stream.Seek(0, SeekOrigin.Begin);
25    }
26
27    public T EncapsulatedObject {
28      get {
29        return this.encapsulatedObject;
30      }
31    }
32
33    public override bool CanRead {
34      get { return this.stream.CanRead; }
35    }
36
37    public override bool CanSeek {
38      get { throw new NotImplementedException(); }
39    }
40
41    public override bool CanWrite {
42      get { throw new NotImplementedException(); }
43    }
44
45    public override void Flush() {
46      throw new NotImplementedException();
47    }
48
49    public override long Length {
50      get { return this.stream.Length; }
51    }
52
53    public override long Position {
54      get {
55        return this.stream.Position;
56      }
57      set {
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.