Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FileWebResponse.cs « System.Net « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4acb6e79e9b93b5d3581908fdae8ce1c87041f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// System.Net.FileWebResponse
//
// Author:
//   Lawrence Pit (loz@cable.a2000.nl)
//

using System;
using System.IO;
using System.Runtime.Serialization;

namespace System.Net 
{
	[Serializable]
	public class FileWebResponse : WebResponse, ISerializable, IDisposable
	{
		private Uri responseUri;
		private FileStream fileStream;
		private long contentLength;
		private WebHeaderCollection webHeaders;
		private bool disposed = false;
		
		// Constructors
		
		protected FileWebResponse () { }
		
		internal FileWebResponse (Uri responseUri, FileStream fileStream)
		{
			try {
				this.responseUri = responseUri;
				this.fileStream = fileStream;
				this.contentLength = fileStream.Length;
				this.webHeaders = new WebHeaderCollection ();
				this.webHeaders.Add ("Content-Length", Convert.ToString (contentLength));
				this.webHeaders.Add ("Content-Type", "binary/octet-stream");
			} catch (Exception e) {
				throw new WebException (e.Message, e);
			}
		}
		
		[MonoTODO]
		protected FileWebResponse (SerializationInfo serializationInfo, StreamingContext streamingContext)
		{
			throw new NotImplementedException ();
		}
		
		// Properties
		
		public override long ContentLength {		
			get {
				try { return this.contentLength; }
				finally { CheckDisposed (); }
			}
		}
		
		public override string ContentType {		
			get {
				try { return "binary/octet-stream"; }
				finally { CheckDisposed (); }
			}
		}
		
		public override WebHeaderCollection Headers {		
			get {
				try { return this.webHeaders; }
				finally { CheckDisposed (); }
			}
		}
		
		public override Uri ResponseUri {		
			get {
				try { return this.responseUri; }
				finally { CheckDisposed (); }
			}
		}		

		// Methods

		[MonoTODO]
		void ISerializable.GetObjectData (SerializationInfo serializationInfo,
		   				  StreamingContext streamingContext)
		{
			try {
				throw new NotImplementedException ();
			} finally { CheckDisposed (); }
		}		

		public override Stream GetResponseStream()
		{
			try { return this.fileStream; }
			finally { CheckDisposed (); }
		}
				
		// Cleaning up stuff
		
		~FileWebResponse ()
		{
			Dispose (false);
		}		
		
		public override void Close()
		{
			((IDisposable) this).Dispose ();
		}

		void IDisposable.Dispose()
		{
			Dispose (true);
			
			// see spec, suppress finalization of this object.
			GC.SuppressFinalize (this);  
		}
		
		protected virtual void Dispose (bool disposing)
		{
			if (this.disposed)
				return;
			this.disposed = true;
			
			if (disposing) {
				// release managed resources
				this.responseUri = null;
				this.webHeaders = null;
			}
			
			// release unmanaged resources
			FileStream stream = fileStream;
			fileStream = null;
			if (stream != null)
				stream.Close (); // also closes webRequest
		}
		
		private void CheckDisposed ()
		{
			if (disposed)
				throw new ObjectDisposedException (GetType ().FullName);
		}		
	}
}