1 //------------------------------------------------------------------------------
2 // <copyright file="SqlStreamChars.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">junfang</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 // <owner current="true" primary="false">Microsoft</owner>
8 //------------------------------------------------------------------------------
10 //**************************************************************************
11 // @File: SqlStreamChars.cs
21 // 04/17/01 JunFang Created.
24 //**************************************************************************
26 namespace System.Data.SqlTypes
30 using System.Runtime.InteropServices;
31 using System.Data.SqlTypes;
33 internal abstract class SqlStreamChars: System.Data.SqlTypes.INullable, IDisposable
35 public abstract bool IsNull { get; }
37 public abstract bool CanRead { get; }
39 public abstract bool CanSeek { get; }
41 public abstract bool CanWrite { get; }
43 public abstract long Length { get; }
45 public abstract long Position { get; set; }
47 // --------------------------------------------------------------
49 // --------------------------------------------------------------
50 public abstract int Read (char[] buffer, int offset, int count);
52 public abstract void Write (char[] buffer, int offset, int count);
54 public abstract long Seek (long offset, SeekOrigin origin);
56 public abstract void SetLength (long value);
58 public abstract void Flush ();
60 public virtual void Close(){
64 void IDisposable.Dispose() {
68 protected virtual void Dispose(bool disposing) {
71 public virtual int ReadChar()
73 // Reads one char from the stream by calling Read(char[], int, int).
74 // Will return an char cast to an int or -1 on end of stream.
75 // The performance of the default implementation on Stream is bad,
76 // and any subclass with an internal buffer should override this method.
77 char[] oneCharArray = new char[1];
78 int r = Read(oneCharArray, 0, 1);
81 return oneCharArray[0];
84 public virtual void WriteChar(char value)
86 // Writes one char from the stream by calling Write(char[], int, int).
87 // The performance of the default implementation on Stream is bad,
88 // and any subclass with an internal buffer should override this method.
89 char[] oneCharArray = new char[1];
90 oneCharArray[0] = value;
91 Write(oneCharArray, 0, 1);
95 // Private class: the Null SqlStreamChars
96 private class NullSqlStreamChars : SqlStreamChars
98 // --------------------------------------------------------------
100 // --------------------------------------------------------------
102 internal NullSqlStreamChars()
107 // --------------------------------------------------------------
109 // --------------------------------------------------------------
111 public override bool IsNull
119 public override bool CanRead
127 public override bool CanSeek
135 public override bool CanWrite
143 public override long Length
147 throw new SqlNullValueException();
151 public override long Position
155 throw new SqlNullValueException();
159 throw new SqlNullValueException();
163 // --------------------------------------------------------------
165 // --------------------------------------------------------------
166 public override int Read (char[] buffer, int offset, int count)
168 throw new SqlNullValueException();
171 public override void Write (char[] buffer, int offset, int count)
173 throw new SqlNullValueException();
176 public override long Seek (long offset, SeekOrigin origin)
178 throw new SqlNullValueException();
181 public override void SetLength (long value)
183 throw new SqlNullValueException();
186 public override void Flush ()
188 throw new SqlNullValueException();
191 public override void Close ()
195 } // class NullSqlStreamChars
199 public static SqlStreamChars Null {
201 return new NullSqlStreamChars();
205 } // class SqlStreamChars
207 } // namespace System.Data.SqlTypes