19 using Lucene.Net.Support;
22 namespace Lucene.Net.Store
37 public abstract void WriteByte(byte b);
46 public virtual void WriteBytes(byte[] b,
int length)
48 WriteBytes(b, 0, length);
60 public abstract void WriteBytes(byte[] b,
int offset,
int length);
65 public virtual void WriteInt(
int i)
67 WriteByte((byte) (i >> 24));
68 WriteByte((byte) (i >> 16));
69 WriteByte((byte) (i >> 8));
79 public virtual void WriteVInt(
int i)
81 while ((i & ~ 0x7F) != 0)
83 WriteByte((byte) ((i & 0x7f) | 0x80));
92 public virtual void WriteLong(
long i)
94 WriteInt((
int) (i >> 32));
104 public virtual void WriteVLong(
long i)
106 while ((i & ~ 0x7F) != 0)
108 WriteByte((byte) ((i & 0x7f) | 0x80));
117 public virtual void WriteString(System.String s)
120 UnicodeUtil.UTF16toUTF8(s, 0, s.Length, utf8Result);
121 WriteVInt(utf8Result.length);
122 WriteBytes(utf8Result.result, 0, utf8Result.length);
137 [Obsolete(
"-- please pre-convert to utf8 bytes instead or use WriteString")]
138 public virtual void WriteChars(System.String s,
int start,
int length)
140 int end = start + length;
141 for (
int i = start; i < end; i++)
143 int code = (int) s[i];
144 if (code >= 0x01 && code <= 0x7F)
145 WriteByte((byte) code);
146 else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0)
148 WriteByte((byte) (0xC0 | (code >> 6)));
149 WriteByte((byte) (0x80 | (code & 0x3F)));
154 WriteByte((byte) (0x80 | ((code >> 6) & 0x3F)));
155 WriteByte((byte) (0x80 | (code & 0x3F)));
171 [Obsolete(
"-- please pre-convert to utf8 bytes instead or use WriteString")]
172 public virtual void WriteChars(
char[] s,
int start,
int length)
174 int end = start + length;
175 for (
int i = start; i < end; i++)
177 int code = (int) s[i];
178 if (code >= 0x01 && code <= 0x7F)
179 WriteByte((byte) code);
180 else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0)
182 WriteByte((byte) (0xC0 | (code >> 6)));
183 WriteByte((byte) (0x80 | (code & 0x3F)));
188 WriteByte((byte) (0x80 | ((code >> 6) & 0x3F)));
189 WriteByte((byte) (0x80 | (code & 0x3F)));
194 private static int COPY_BUFFER_SIZE = 16384;
195 private byte[] copyBuffer;
198 public virtual void CopyBytes(
IndexInput input,
long numBytes)
200 System.Diagnostics.Debug.Assert(numBytes >= 0,
"numBytes=" + numBytes);
201 long left = numBytes;
202 if (copyBuffer == null)
203 copyBuffer =
new byte[COPY_BUFFER_SIZE];
207 if (left > COPY_BUFFER_SIZE)
208 toCopy = COPY_BUFFER_SIZE;
212 WriteBytes(copyBuffer, 0, toCopy);
218 public abstract void Flush();
221 [Obsolete(
"Use Dispose() instead.")]
228 public void Dispose()
233 protected abstract void Dispose(
bool disposing);
240 public abstract long FilePointer {
get; }
245 public abstract void Seek(
long pos);
248 public abstract long Length {
get; }
262 public virtual void SetLength(
long length)
268 public virtual void WriteStringStringMap(System.Collections.Generic.IDictionary<
string,
string> map)
277 foreach (var entry
in map)
279 WriteString(entry.Key);
280 WriteString(entry.Value);