19 using Lucene.Net.Support;
24 using Lock = Lucene.Net.Store.Lock;
26 namespace Lucene.Net.Index
37 private readonly
int readBufferSize;
39 private sealed
class FileEntry
45 private bool isDisposed;
49 private readonly System.String fileName;
52 private HashMap<string, FileEntry> entries =
new HashMap<string, FileEntry>();
63 this.readBufferSize = readBufferSize;
69 stream = dir.
OpenInput(name, readBufferSize);
72 int count = stream.ReadVInt();
73 FileEntry entry = null;
74 for (
int i = 0; i < count; i++)
76 long offset = stream.ReadLong();
77 System.String
id = stream.ReadString();
82 entry.length = offset - entry.offset;
85 entry =
new FileEntry {offset = offset};
92 entry.length = stream.Length() - entry.offset;
99 if (!success && (stream != null))
105 catch (System.IO.IOException)
114 get {
return directory; }
117 public virtual string Name
119 get {
return fileName; }
122 protected override void Dispose(
bool disposing)
126 if (isDisposed)
return;
150 return OpenInput(
id, readBufferSize);
154 public override IndexInput OpenInput(System.String
id,
int readBufferSize)
159 throw new System.IO.IOException(
"Stream closed");
161 FileEntry entry = entries[id];
163 throw new System.IO.IOException(
"No sub-file with id " +
id +
" found");
165 return new CSIndexInput(stream, entry.offset, entry.length, readBufferSize);
170 public override System.String[] ListAll()
172 return entries.Keys.ToArray();
176 public override bool FileExists(System.String name)
178 return entries.ContainsKey(name);
182 public override long FileModified(System.String name)
184 return directory.FileModified(fileName);
188 public override void TouchFile(System.String name)
190 directory.TouchFile(fileName);
195 public override void DeleteFile(System.String name)
197 throw new System.NotSupportedException();
202 public void RenameFile(System.String from, System.String to)
204 throw new System.NotSupportedException();
209 public override long FileLength(System.String name)
211 FileEntry e = entries[name];
213 throw new System.IO.IOException(
"File " + name +
" does not exist");
221 throw new System.NotSupportedException();
226 public override Lock MakeLock(System.String name)
228 throw new System.NotSupportedException();
239 internal long fileOffset;
240 internal long length;
242 private bool isDisposed;
248 internal CSIndexInput(
IndexInput @base,
long fileOffset,
long length,
int readBufferSize):base(readBufferSize)
250 this.base_Renamed = (
IndexInput) @base.Clone();
251 this.fileOffset = fileOffset;
252 this.length = length;
255 public override System.Object Clone()
258 clone.base_Renamed = (
IndexInput) base_Renamed.Clone();
259 clone.fileOffset = fileOffset;
260 clone.length = length;
273 public override void ReadInternal(byte[] b,
int offset,
int len)
275 long start = FilePointer;
276 if (start + len > length)
277 throw new System.IO.IOException(
"read past EOF");
278 base_Renamed.Seek(fileOffset + start);
279 base_Renamed.ReadBytes(b, offset, len,
false);
287 public override void SeekInternal(
long pos)
291 protected override void Dispose(
bool disposing)
293 if (isDisposed)
return;
297 if (base_Renamed != null)
299 base_Renamed.Close();
306 public override long Length()
313 get {
return base_Renamed; }