HttpResponseStream.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // System.Web.HttpResponseStream
  3. //
  4. // Author:
  5. // Patrik Torstensson ([email protected])
  6. //
  7. using System;
  8. using System.IO;
  9. namespace System.Web {
  10. /// <summary>
  11. /// Simple wrapper around HttpWriter to support the Stream interface
  12. /// </summary>
  13. class HttpResponseStream : Stream {
  14. private HttpWriter _Writer;
  15. internal HttpResponseStream(HttpWriter Writer) {
  16. _Writer = Writer;
  17. }
  18. public override void Flush() {
  19. _Writer.Flush();
  20. }
  21. public override void Close() {
  22. _Writer.Close();
  23. }
  24. public override int Read(byte [] buffer, int offset, int length) {
  25. throw new NotSupportedException();
  26. }
  27. public override long Seek(long offset, SeekOrigin origin) {
  28. throw new NotSupportedException();
  29. }
  30. public override void SetLength(long length) {
  31. throw new NotSupportedException();
  32. }
  33. public override void Write(byte [] buffer, int offset, int length) {
  34. if (offset < 0) {
  35. throw new ArgumentOutOfRangeException("offset");
  36. }
  37. if (length <= 0) {
  38. throw new ArgumentOutOfRangeException("length");
  39. }
  40. _Writer.WriteBytes(buffer, offset, length);
  41. }
  42. public override bool CanRead {
  43. get {
  44. return false;
  45. }
  46. }
  47. public override bool CanSeek {
  48. get {
  49. return false;
  50. }
  51. }
  52. public override bool CanWrite {
  53. get {
  54. return true;
  55. }
  56. }
  57. public override long Length {
  58. get {
  59. throw new NotSupportedException();
  60. }
  61. }
  62. public override long Position {
  63. get {
  64. throw new NotSupportedException();
  65. }
  66. set {
  67. throw new NotSupportedException();
  68. }
  69. }
  70. }
  71. }