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)
					{
					}
				}
			}
		}
Exemple #2
0
        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)
                    {
                    }
                }
            }
        }
Exemple #3
0
        private void  Read(InputStream input)
        {
            int size = input.ReadVInt(); //read in the size

            for (int i = 0; i < size; i++)
            {
                System.String name            = String.Intern(input.ReadString());
                byte          bits            = input.ReadByte();
                bool          isIndexed       = (bits & 0x1) != 0;
                bool          storeTermVector = (bits & 0x2) != 0;
                AddInternal(name, isIndexed, storeTermVector);
            }
        }
        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 #5
0
        public /*internal*/ Document Doc(int n)
        {
            indexStream.Seek(n * 8L);
            long position = indexStream.ReadLong();

            fieldsStream.Seek(position);

            Document doc       = new Document();
            int      numFields = fieldsStream.ReadVInt();

            for (int i = 0; i < numFields; i++)
            {
                int       fieldNumber = fieldsStream.ReadVInt();
                FieldInfo fi          = fieldInfos.FieldInfo(fieldNumber);

                byte bits = fieldsStream.ReadByte();

                doc.Add(new Field(fi.name, fieldsStream.ReadString(), true, fi.isIndexed, (bits & 1) != 0, fi.storeTermVector));                 // vector
            }

            return(doc);
        }
        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);
        }
Exemple #7
0
		private void  Read(InputStream input)
		{
			int size = input.ReadVInt(); //read in the size
			for (int i = 0; i < size; i++)
			{
				System.String name = String.Intern(input.ReadString());
				byte bits = input.ReadByte();
				bool isIndexed = (bits & 0x1) != 0;
				bool storeTermVector = (bits & 0x2) != 0;
				AddInternal(name, isIndexed, storeTermVector);
			}
		}