/// <summary>Read norms into a pre-allocated array. </summary> public override void Norms(System.String field, byte[] bytes, int offset) { lock (this) { Norm norm = (Norm)norms[field]; if (norm == null) { return; // use zeros in array } if (norm.bytes != null) { // can copy from cache Array.Copy(norm.bytes, 0, bytes, offset, MaxDoc()); return; } InputStream normStream = (InputStream)norm.in_Renamed.Clone(); try { // read from disk normStream.Seek(0); normStream.ReadBytes(bytes, offset, MaxDoc()); } finally { normStream.Close(); } } }
protected internal override void DoClose() { fieldsReader.Close(); tis.Close(); if (freqStream != null) { freqStream.Close(); } if (proxStream != null) { proxStream.Close(); } CloseNorms(); if (termVectorsReader != null) { termVectorsReader.Close(); } if (cfsReader != null) { cfsReader.Close(); } }
public virtual void Close() { freqStream.Close(); if (skipStream != null) { skipStream.Close(); } }
public CompoundFileReader(Directory dir, System.String name) { directory = dir; fileName = name; bool success = false; try { stream = dir.OpenFile(name); // read the directory and init files int count = stream.ReadVInt(); FileEntry entry = null; for (int i = 0; i < count; i++) { long offset = stream.ReadLong(); System.String id = stream.ReadString(); if (entry != null) { // set length of the previous entry entry.length = offset - entry.offset; } entry = new FileEntry(); entry.offset = offset; entries[id] = entry; } // set the length of the final entry if (entry != null) { entry.length = stream.Length() - entry.offset; } success = true; } finally { if (!success && (stream != null)) { try { stream.Close(); } catch (System.IO.IOException e) { } } } }
/// <summary> Construct a FieldInfos object using the directory and the name of the file /// InputStream /// </summary> /// <param name="d">The directory to open the InputStream from /// </param> /// <param name="name">The name of the file to open the InputStream from in the Directory /// </param> /// <throws> IOException </throws> /// <summary> /// </summary> /// <seealso cref="#read"> /// </seealso> public /*internal*/ FieldInfos(Directory d, System.String name) { InputStream input = d.OpenFile(name); try { Read(input); } finally { input.Close(); } }
internal virtual void Close() { lock (this) { // why don't we trap the exception and at least make sure that // all streams that we can close are closed? if (tvx != null) tvx.Close(); if (tvd != null) tvd.Close(); if (tvf != null) tvf.Close(); } }
public void Read(Directory directory) { InputStream input = directory.OpenFile("segments"); try { int format = input.ReadInt(); if (format < 0) { // file contains explicit format info // check that it is a format we can understand if (format < FORMAT) { throw new System.IO.IOException("Unknown format version: " + format); } version = input.ReadLong(); // read version counter = input.ReadInt(); // read counter } else { // file is in old format without explicit format info counter = format; } for (int i = input.ReadInt(); i > 0; i--) { // read segmentInfos SegmentInfo si = new SegmentInfo(input.ReadString(), input.ReadInt(), directory); Add(si); } if (format >= 0) { // in old format the version number may be at the end of the file if (input.GetFilePointer() >= input.Length()) { version = 0; } // old file format without version number else { version = input.ReadLong(); // read version } } } finally { input.Close(); } }
/// <summary>Constructs a bit vector from the file <code>name</code> in Directory /// <code>d</code>, as written by the {@link #write} method. /// </summary> public BitVector(Directory d, System.String name) { InputStream input = d.OpenFile(name); try { size = input.ReadInt(); // read size count = input.ReadInt(); // read count bits = new byte[(size >> 3) + 1]; // allocate bits input.ReadBytes(bits, 0, bits.Length); // read bits } finally { input.Close(); } }
/// <summary>Copy the contents of the file with specified extension into the /// provided output stream. Use the provided buffer for moving data /// to reduce memory allocation. /// </summary> private void CopyFile(FileEntry source, OutputStream os, byte[] buffer) { InputStream is_Renamed = null; try { long startPtr = os.GetFilePointer(); is_Renamed = directory.OpenFile(source.file); long length = is_Renamed.Length(); long remainder = length; int chunk = buffer.Length; while (remainder > 0) { int len = (int)System.Math.Min(chunk, remainder); is_Renamed.ReadBytes(buffer, 0, len); os.WriteBytes(buffer, len); remainder -= len; } // Verify that remainder is 0 if (remainder != 0) { throw new System.IO.IOException("Non-zero remainder length after copying: " + remainder + " (id: " + source.file + ", length: " + length + ", buffer size: " + chunk + ")"); } // Verify that the output length diff is equal to original file long endPtr = os.GetFilePointer(); long diff = endPtr - startPtr; if (diff != length) { throw new System.IO.IOException("Difference in the output file offsets " + diff + " does not match the original file length " + length); } } finally { if (is_Renamed != null) { is_Renamed.Close(); } } }
private System.Collections.ArrayList ReadDeleteableFiles() { System.Collections.ArrayList result = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); if (!directory.FileExists("deletable")) { return(result); } InputStream input = directory.OpenFile("deletable"); try { for (int i = input.ReadInt(); i > 0; i--) { // read file names result.Add(input.ReadString()); } } finally { input.Close(); } return(result); }
/// <summary> Current version number from segments file.</summary> public static long ReadCurrentVersion(Directory directory) { InputStream input = directory.OpenFile("segments"); int format = 0; long version = 0; try { format = input.ReadInt(); if (format < 0) { if (format < FORMAT) { throw new System.IO.IOException("Unknown format version: " + format); } version = input.ReadLong(); // read version } } finally { input.Close(); } if (format < 0) { return(version); } // We cannot be sure about the format of the file. // Therefore we have to read the whole file and cannot simply seek to the version entry. SegmentInfos sis = new SegmentInfos(); sis.Read(directory); return(sis.GetVersion()); }
public override void Close() { base.Close(); proxStream.Close(); }
/// <summary>Closes the enumeration to further activity, freeing resources. </summary> public override void Close() { input.Close(); }
public /*internal*/ void Close() { fieldsStream.Close(); indexStream.Close(); }