2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16 * All Rights Reserved.
23 using System.Collections;
25 namespace FirebirdSql.Data.Common
27 internal abstract class BlobBase
32 private Charset charset;
33 private int segmentSize;
37 #region Protected Fields
39 protected long blobId;
40 protected int blobHandle;
41 protected int position;
42 protected ITransaction transaction;
50 get { return this.blobHandle; }
55 get { return this.blobId; }
60 get { return (this.rblFlags & IscCodes.RBL_eof_pending) != 0; }
65 #region Protected Properties
67 protected int SegmentSize
69 get { return this.segmentSize; }
74 #region Abstract Properties
76 public abstract IDatabase DB
85 protected BlobBase(IDatabase db)
87 this.segmentSize = db.PacketSize;
88 this.charset = db.Charset;
93 #region Protected Abstract Methods
95 protected abstract void Create();
96 protected abstract void Open();
97 protected abstract byte[] GetSegment();
98 protected abstract void PutSegment(byte[] buffer);
99 protected abstract void Seek(int position);
100 protected abstract void GetBlobInfo();
101 protected abstract void Close();
102 protected abstract void Cancel();
108 public string ReadString()
110 byte[] buffer = this.Read();
111 return this.charset.GetString(buffer, 0, buffer.Length);
116 MemoryStream ms = new MemoryStream();
124 byte[] segment = this.GetSegment();
125 ms.Write(segment, 0, segment.Length);
132 // Cancel the blob and rethrow the exception
141 public void Write(string data)
143 this.Write(this.charset.GetBytes(data));
146 public void Write(byte[] buffer)
148 this.Write(buffer, 0, buffer.Length);
151 public void Write(byte[] buffer, int index, int count)
157 byte[] tmpBuffer = null;
161 int chunk = length >= this.segmentSize ? this.segmentSize : length;
163 tmpBuffer = new byte[chunk];
170 tmpBuffer = new byte[chunk];
172 System.Array.Copy(buffer, offset, tmpBuffer, 0, chunk);
173 this.PutSegment(tmpBuffer);
183 // Cancel the blob and rethrow the exception
192 #region Protected Methods
194 protected void RblAddValue(int rblValue)
196 this.rblFlags |= rblValue;
199 protected void RblRemoveValue(int rblValue)
201 this.rblFlags &= ~rblValue;