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();
            }
        }
Exemple #2
0
        internal SegmentTermEnum(InputStream i, FieldInfos fis, bool isi)
        {
            input      = i;
            fieldInfos = fis;
            isIndex    = isi;

            int firstInt = input.ReadInt();

            if (firstInt >= 0)
            {
                // original-format file, without explicit format version number
                format = 0;
                size   = firstInt;

                // back-compatible settings
                indexInterval = 128;
                skipInterval  = System.Int32.MaxValue;                // switch off skipTo optimization
            }
            else
            {
                // we have a format version number
                format = firstInt;

                // check that it is a format we can understand
                if (format < TermInfosWriter.FORMAT)
                {
                    throw new System.IO.IOException("Unknown format version:" + format);
                }

                size = input.ReadLong();                 // read the size

                if (format == -1)
                {
                    if (!isIndex)
                    {
                        indexInterval        = input.ReadInt();
                        formatM1SkipInterval = input.ReadInt();
                    }
                    // switch off skipTo optimization for file format prior to 1.4rc2 in order to avoid a bug in
                    // skipTo implementation of these versions
                    skipInterval = System.Int32.MaxValue;
                }
                else
                {
                    indexInterval = input.ReadInt();
                    skipInterval  = input.ReadInt();
                }
            }
        }
        /// <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();
            }
        }
		internal SegmentTermEnum(InputStream i, FieldInfos fis, bool isi)
		{
			input = i;
			fieldInfos = fis;
			isIndex = isi;
			
			int firstInt = input.ReadInt();
			if (firstInt >= 0)
			{
				// original-format file, without explicit format version number
				format = 0;
				size = firstInt;
				
				// back-compatible settings
				indexInterval = 128;
				skipInterval = System.Int32.MaxValue; // switch off skipTo optimization
			}
			else
			{
				// we have a format version number
				format = firstInt;
				
				// check that it is a format we can understand
				if (format < TermInfosWriter.FORMAT)
					throw new System.IO.IOException("Unknown format version:" + format);
				
				size = input.ReadLong(); // read the size
				
				if (format == - 1)
				{
					if (!isIndex)
					{
						indexInterval = input.ReadInt();
						formatM1SkipInterval = input.ReadInt();
					}
					// switch off skipTo optimization for file format prior to 1.4rc2 in order to avoid a bug in 
					// skipTo implementation of these versions
					skipInterval = System.Int32.MaxValue;
				}
				else
				{
					indexInterval = input.ReadInt();
					skipInterval = input.ReadInt();
				}
			}
		}
Exemple #5
0
		private void  CheckValidFormat(InputStream in_Renamed)
		{
			int format = in_Renamed.ReadInt();
			if (format > TermVectorsWriter.FORMAT_VERSION)
			{
				throw new System.IO.IOException("Incompatible format version: " + format + " expected " + TermVectorsWriter.FORMAT_VERSION + " or less");
			}
		}
        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());
        }