2 * Copyright (c) 2002-2003 Mainsoft Corporation.
3 * Copyright (C) 2004 Novell, Inc (http://www.novell.com)
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
29 using Microsoft.VisualBasic;
30 using Microsoft.VisualBasic.CompilerServices;
32 public class BinaryVBFile : RandomVBFile
34 public BinaryVBFile(String fileName, OpenMode mode, OpenAccess access, int recordLength) :
35 base(fileName,mode,access,recordLength)
40 public override bool canWrite()
45 public override bool canRead()
50 private String readString()
52 StringBuilder sb = new StringBuilder("");
53 int cInt = _binaryReader.Read();
56 while (cInt != -1 && !(c == ',' && !inStr) && c != '\r') //spacebar
58 if (c == '\"' && inStr)
61 if ((char) _binaryReader.PeekChar() == ',')
68 cInt = _binaryReader.Read();
75 && sb[sb.Length - 1] == '\"')
78 sb.Remove(sb.Length - 1, 1);
83 private String readNumber()
85 StringBuilder sb = new StringBuilder();
86 int cInt = _binaryReader.Read();
88 while (cInt != -1 && c != ',' && c != '\r' && c != 32) //spacebar
91 cInt = _binaryReader.Read();
97 public override void Input(out bool Value)
99 String str = readString().Trim();
101 if (str[0] == '#' && str.Length != 1)
102 str = str.Substring(1, str.Length - 1);
105 Value = BooleanType.FromObject(obj);
108 public override void Input(out byte Value)
110 char val = this._binaryReader.ReadChar();
111 while (val == 10 || val == 32)
112 val = this._binaryReader.ReadChar();
113 String str = readString().Trim();
114 Value = ByteType.FromString(val+str);
117 public override void Input(out short Value)
119 char val = this._binaryReader.ReadChar();
120 while (val == 10 || val == 32)
121 val = this._binaryReader.ReadChar();
122 String str = readString().Trim();
123 Value = ShortType.FromString(val+str);
126 public override void Input(out int Value)
128 char val = this._binaryReader.ReadChar();
129 while (val == 10 || val == 32)
130 val = this._binaryReader.ReadChar();
131 String str = readString().Trim();
132 Value = IntegerType.FromString(val+str);
135 public override void Input(out long Value)
137 char val = this._binaryReader.ReadChar();
138 while (val == 10 || val == 32)
139 val = this._binaryReader.ReadChar();
140 String str = readString().Trim();
141 Value = LongType.FromString(val+str);
144 public override void Input(out char Value)
146 char val = this._binaryReader.ReadChar();
147 while (val == 10 || val == 32)
148 val = this._binaryReader.ReadChar();
149 String str = readString().Trim();
150 Value = CharType.FromString(val+str);
153 public override void Input(out float Value)
155 char val = this._binaryReader.ReadChar();
156 while (val == 10 || val == 32)
157 val = this._binaryReader.ReadChar();
158 String str = readString().Trim();
159 Value = SingleType.FromString(val+str);
162 public override void Input(out double Value)
164 char val = this._binaryReader.ReadChar();
165 while (val == 10 || val == 32)
166 val = this._binaryReader.ReadChar();
167 String str = readString().Trim();
168 Value = DoubleType.FromString(val+str);
171 public override void Input(out Decimal Value)
173 char val = (char)this._binaryReader.PeekChar();
174 while (val == 10 || val == 32)
176 this._binaryReader.ReadChar();
177 val = (char)this._binaryReader.PeekChar();
179 String str = readString().Trim();
180 Value = DecimalType.FromString(str);
183 public override string Input(string val)
185 return readString()/*.Trim()*/;
188 public DateTime Input( DateTime Value)
190 String str = readString().Trim();
191 if (str[0] == '#' && str.Length != 1)
192 str = str.Substring(1, str.Length - 1);
193 return DateTime.Parse(str);
196 public override string InputString(int count)
199 StringBuilder sb = new StringBuilder("");
203 current = this._binaryReader.Read();
204 if (current == -1 || current == 26)
205 throw (EndOfStreamException) ExceptionUtils.VbMakeException(VBErrors.EndOfFile);
206 sb.Append((char)current);
209 return sb.ToString();
213 public override long seek()
215 return getPosition() + 1;
218 public override void seek(long position)
221 throw (IOException) ExceptionUtils.VbMakeException(
222 VBErrors.BadRecordNum);
223 setPosition(position - 1);
226 public override string readLine()