Files
mono/mcs/class/System/System.Net/FileWebResponse.cs
T
Lawrence Pit 9660a4c88b * Dns.cs: Reimplemented (simplified and fixed) asynchronous methods by
relying on standard asynchronous delegate features. Added checks for
	null strings.
	* HttpWebResponse.cs: implemented properties
	* FileWebResponse.cs: improved the way resources are disposed.
	* FileWebRequest.cs: started implementation of asynchronous methods
	* ServicePointManager.cs: implemented properties

svn path=/trunk/mcs/; revision=4604
2002-05-13 19:59:05 +00:00

139 lines
2.9 KiB
C#

//
// System.Net.FileWebResponse
//
// Author:
// Lawrence Pit ([email protected])
//
using System;
using System.IO;
using System.Runtime.Serialization;
namespace System.Net
{
[Serializable]
public class FileWebResponse : WebResponse, ISerializable, IDisposable
{
private FileWebRequest webRequest;
private FileStream fileStream;
private long contentLength;
private WebHeaderCollection webHeaders;
private bool disposed = false;
// Constructors
protected FileWebResponse () { }
internal FileWebResponse (FileWebRequest webRequest, FileStream fileStream)
{
try {
this.webRequest = webRequest;
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 {
CheckDisposed ();
return this.contentLength;
}
}
public override string ContentType {
get {
CheckDisposed ();
return "binary/octet-stream";
}
}
public override WebHeaderCollection Headers {
get {
CheckDisposed ();
return this.webHeaders;
}
}
public override Uri ResponseUri {
get {
CheckDisposed ();
return this.webRequest.RequestUri;
}
}
// Methods
[MonoTODO]
void ISerializable.GetObjectData (SerializationInfo serializationInfo,
StreamingContext streamingContext)
{
CheckDisposed ();
throw new NotImplementedException ();
}
public override Stream GetResponseStream()
{
CheckDisposed ();
return this.fileStream;
}
// 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.disposed = true;
this.webRequest = null;
this.webHeaders = null;
}
// release unmanaged resources
Stream stream = fileStream;
fileStream = null;
if (stream != null)
stream.Close ();
}
private void CheckDisposed ()
{
if (disposed)
throw new ObjectDisposedException ("stream");
}
}
}