19 using Lucene.Net.Support;
21 namespace Lucene.Net.Store
29 public abstract class IndexInput : System.ICloneable, IDisposable
31 private bool preUTF8Strings;
36 public abstract byte ReadByte();
47 public abstract void ReadBytes(byte[] b,
int offset,
int len);
66 public virtual void ReadBytes(byte[] b,
int offset,
int len,
bool useBuffer)
69 ReadBytes(b, offset, len);
75 public virtual int ReadInt()
77 return ((ReadByte() & 0xFF) << 24) | ((ReadByte() & 0xFF) << 16) | ((ReadByte() & 0xFF) << 8) | (ReadByte() & 0xFF);
86 public virtual int ReadVInt()
90 for (
int shift = 7; (b & 0x80) != 0; shift += 7)
93 i |= (b & 0x7F) << shift;
101 public virtual long ReadLong()
103 return (((
long) ReadInt()) << 32) | (ReadInt() & 0xFFFFFFFFL);
110 public virtual long ReadVLong()
114 for (
int shift = 7; (b & 0x80) != 0; shift += 7)
117 i |= (b & 0x7FL) << shift;
127 public virtual void SetModifiedUTF8StringsMode()
129 preUTF8Strings =
true;
135 public virtual System.String ReadString()
138 return ReadModifiedUTF8String();
139 int length = ReadVInt();
140 byte[] bytes =
new byte[length];
141 ReadBytes(bytes, 0, length);
142 return System.Text.Encoding.UTF8.GetString(bytes, 0, length);
145 private System.String ReadModifiedUTF8String()
147 int length = ReadVInt();
148 char[] chars =
new char[length];
149 ReadChars(chars, 0, length);
150 return new System.String(chars, 0, length);
168 [Obsolete(
"-- please use ReadString or ReadBytes instead, and construct the string from those utf8 bytes")]
169 public virtual void ReadChars(
char[] buffer,
int start,
int length)
171 int end = start + length;
172 for (
int i = start; i < end; i++)
176 buffer[i] = (char) (b & 0x7F);
177 else if ((b & 0xE0) != 0xE0)
179 buffer[i] = (char) (((b & 0x1F) << 6) | (ReadByte() & 0x3F));
182 buffer[i] = (char) (((b & 0x0F) << 12) | ((ReadByte() & 0x3F) << 6) | (ReadByte() & 0x3F));
198 [Obsolete(
"this method operates on old \"modified utf8\" encoded strings")]
199 public virtual void SkipChars(
int length)
201 for (
int i = 0; i < length; i++)
208 else if ((b & 0xE0) != 0xE0)
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();
259 public virtual System.Object Clone()
266 catch (System.Exception)
274 public virtual System.Collections.Generic.IDictionary<string,
string> ReadStringStringMap()
276 var map =
new HashMap<string, string>();
277 int count = ReadInt();
278 for (
int i = 0; i < count; i++)
280 System.String key = ReadString();
281 System.String val = ReadString();