20 namespace Lucene.Net.Store
41 : base(path, lockFactory)
59 return new SimpleFSIndexOutput(
new System.IO.FileInfo(System.IO.Path.Combine(internalDirectory.FullName, name)));
63 public override IndexInput OpenInput(System.String name,
int bufferSize)
68 for (var i = 0; i < 10; i++)
72 return new SimpleFSIndexInput(
new System.IO.FileInfo(
73 System.IO.Path.Combine(internalDirectory.FullName, name)), bufferSize, ReadChunkSize);
75 catch (System.UnauthorizedAccessException ex)
78 System.Threading.Thread.Sleep(1);
88 protected internal class Descriptor : System.IO.BinaryReader
92 protected internal volatile bool isOpen;
93 internal long position;
96 private bool isDisposed;
98 public Descriptor( System.IO.FileInfo file, System.IO.FileAccess mode)
99 : base(new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, mode, System.IO.FileShare.ReadWrite))
102 length = file.Length;
105 protected override void Dispose(
bool disposing)
107 if (isDisposed)
return;
118 base.Dispose(disposing);
133 protected internal Descriptor file;
134 internal bool isClone;
135 private bool isDisposed;
137 protected internal int chunkSize;
139 public SimpleFSIndexInput(System.IO.FileInfo path,
int bufferSize,
int chunkSize)
142 file =
new Descriptor(path, System.IO.FileAccess.Read);
143 this.chunkSize = chunkSize;
147 public override void ReadInternal(byte[] b,
int offset,
int len)
151 long position = FilePointer;
152 if (position != file.position)
154 file.BaseStream.Seek(position, System.IO.SeekOrigin.Begin);
155 file.position = position;
164 if (total + chunkSize > len)
166 readLength = len - total;
171 readLength = chunkSize;
173 int i = file.Read(b, offset + total, readLength);
176 throw new System.IO.IOException(
"read past EOF");
183 catch (System.OutOfMemoryException e)
187 System.OutOfMemoryException outOfMemoryError =
new System.OutOfMemoryException(
"OutOfMemoryError likely caused by the Sun VM Bug described in " +
"https://issues.apache.org/jira/browse/LUCENE-1566; try calling FSDirectory.setReadChunkSize " +
"with a a value smaller than the current chunks size (" + chunkSize +
")", e);
188 throw outOfMemoryError;
193 protected override void Dispose(
bool disposing)
195 if (isDisposed)
return;
199 if (!isClone && file != null)
209 public override void SeekInternal(
long position)
213 public override long Length()
218 public override System.Object Clone()
220 SimpleFSIndexInput clone = (SimpleFSIndexInput) base.Clone();
221 clone.isClone =
true;
228 public virtual bool IsFDValid()
230 return file.BaseStream != null;
233 public bool isClone_ForNUnit
235 get {
return isClone; }
241 internal System.IO.FileStream file = null;
245 private volatile bool isOpen;
249 file =
new System.IO.FileStream(path.FullName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
254 public override void FlushBuffer(byte[] b,
int offset,
int size)
256 file.Write(b, offset, size);
270 protected override void Dispose(
bool disposing)
275 bool success =
false;
278 base.Dispose(disposing);
290 catch (System.Exception)
302 public override void Seek(
long pos)
305 file.Seek(pos, System.IO.SeekOrigin.Begin);
308 public override long Length
310 get {
return file.Length; }
313 public override void SetLength(
long length)
315 file.SetLength(length);