ObexWebResponse.cs :  » Business-Application » 32feet.NET » InTheHand » Net » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » 32feet.NET 
32feet.NET » InTheHand » Net » ObexWebResponse.cs
// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.ObexWebResponse
// 
// Copyright (c) 2003-2008 In The Hand Ltd, All rights reserved.
// This source code is licensed under the In The Hand Community License - see License.txt

using System.Net;
using System.IO;

namespace InTheHand.Net{
  /// <summary>
  /// Provides an OBEX implementation of the <see cref="WebResponse"/> class.
  /// </summary>
  public class ObexWebResponse : WebResponse
  {
    private MemoryStream responseStream;
    private WebHeaderCollection responseHeaders;
    private ObexStatusCode statusCode;

    internal ObexWebResponse(MemoryStream stream, WebHeaderCollection headers, ObexStatusCode code)
    {
      this.responseStream = stream;
      this.responseHeaders = headers;
      this.statusCode = code;
        }

        #region Headers
        /// <summary>
    /// Gets the headers associated with this response from the server.
    /// </summary>
    public override WebHeaderCollection Headers
    {
      get
      {
        return this.responseHeaders;
      }
        }
        #endregion

        #region Content Length
        /// <summary>
        /// Gets the length of the content returned by the request.
    /// </summary>
    public override long ContentLength
    {
      get
      {
        string len = this.responseHeaders["LENGTH"];
        if(len!=null && len!=string.Empty)
        {
          return long.Parse(len);
        }
        return 0;
      }
      set
      {
      }
        }
        #endregion

        #region Content Type
        /// <summary>
        /// Gets the content type of the response.
    /// </summary>
    public override string ContentType
    {
      get
      {
        return this.responseHeaders["TYPE"];
      }
      set
      {
      }
        }
        #endregion

        #region Status Code
        /// <summary>
    /// Returns a status code to indicate the outcome of the request.
    /// </summary>
        /// -
        /// <remarks><para>Note, if a error occurs locally then the status code
        /// <see cref="F:InTheHand.Net.ObexStatusCode.InternalServerError"/> is returned.
        /// Therefore that error code could signal local or remote errors.
        /// </para>
        /// </remarks>
    public ObexStatusCode StatusCode
    {
      get
      {
        return statusCode;
      }
        }
        #endregion

        #region GetResponseStream
        /// <summary>
    /// Gets the stream used to read the body of the response from the server.
    /// </summary>
    /// <returns></returns>
    public override Stream GetResponseStream()
    {
      return responseStream;
        }
        #endregion      

        #region Close
        /// <summary>
    /// Frees the resources held by the response.
    /// </summary>
    public override void Close()
    {
      if(responseStream!=null)
      {
        responseStream.Close();
      }
        }
        #endregion


        #region WriteFile
        /// <summary>
    /// Writes the contents of the response to the specified file path.
    /// </summary>
    /// <param name="fileName">The filename (including the path) from which to read.</param>
        [System.Obsolete()]
    public void WriteFile(string fileName)
    {
      FileStream fs = File.Create(fileName);

      //read in 1k chunks
      byte[] buffer = new byte[1024];
      int readBytes;
      do
      {
        readBytes = responseStream.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, readBytes);
      }while (readBytes > 0);

      responseStream.Close();
      fs.Close();
        }
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.