/// <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();
                }
            }
        }
Exemple #2
0
 /// <summary>Expert: implements buffer refill.  Reads bytes from the current
 /// position in the input.
 /// </summary>
 /// <param name="b">the array to read bytes into
 /// </param>
 /// <param name="offset">the offset in the array to start storing bytes
 /// </param>
 /// <param name="length">the number of bytes to read
 /// </param>
 public override void  ReadInternal(byte[] b, int offset, int len)
 {
     lock (base_Renamed)
     {
         long start = GetFilePointer();
         if (start + len > length)
         {
             throw new System.IO.IOException("read past EOF");
         }
         base_Renamed.Seek(fileOffset + start);
         base_Renamed.ReadBytes(b, offset, len);
     }
 }
        /// <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();
            }
        }
Exemple #4
0
        /// <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();
                }
            }
        }