public override int GetOrd(int docId)
            {
                if (docId < 0 || docId >= _outerInstance.maxDoc)
                {
                    throw new IndexOutOfRangeException("docID must be 0 .. " + (_outerInstance.maxDoc - 1) + "; got " +
                                                       docId);
                }

                try
                {
                    _input.Seek(_field.DataStartFilePointer + _field.NumValues * (9 + _field.Pattern.Length + _field.MaxLength) +
                                docId * (1 + _field.OrdPattern.Length));
                    SimpleTextUtil.ReadLine(_input, _scratch);
                    try
                    {
                        // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                        return(int.Parse(_scratch.Utf8ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture) - 1);
                    }
                    catch (Exception pe)
                    {
                        var e = new CorruptIndexException("failed to parse ord (resource=" + _input + ")", pe);
                        throw e;
                    }
                }
                catch (System.IO.IOException ioe)
                {
                    throw new Exception(ioe.ToString(), ioe);
                }
            }
 public override int getOrd(int docID)
 {
     if (docID < 0 || docID >= outerInstance.maxDoc)
     {
         throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
     }
     try
     {
         @in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.Length + field.maxLength) + docID * (1 + field.ordPattern.Length));
         SimpleTextUtil.ReadLine(@in, scratch);
         try
         {
             return((long)(int)ordDecoder.parse(scratch.utf8ToString()) - 1);
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse ord (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override void lookupOrd(long ord, BytesRef result)
 {
     try
     {
         if (ord < 0 || ord >= field.numValues)
         {
             throw new System.IndexOutOfRangeException("ord must be 0 .. " + (field.numValues - 1) + "; got " + ord);
         }
         @in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.Length + field.maxLength));
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH), "got " + scratch.utf8ToString() + " in=" + @in);
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         result.bytes  = new sbyte[len];
         result.offset = 0;
         result.length = len;
         @in.readBytes(result.bytes, 0, len);
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override bool get(int index)
 {
     try
     {
         @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * index);
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         // skip past bytes
         sbyte[] bytes = new sbyte[len];
         @in.readBytes(bytes, 0, len);
         SimpleTextUtil.ReadLine(@in, scratch);       // newline
         SimpleTextUtil.ReadLine(@in, scratch);       // 'T' or 'F'
         return(scratch.bytes[scratch.offset] == (sbyte)'T');
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override void get(int docID, BytesRef result)
 {
     try
     {
         if (docID < 0 || docID >= outerInstance.maxDoc)
         {
             throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
         }
         @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * docID);
         SimpleTextUtil.ReadLine(@in, scratch);
         Debug.Assert(StringHelper.StartsWith(scratch, LENGTH));
         int len;
         try
         {
             len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8));
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         result.bytes  = new sbyte[len];
         result.offset = 0;
         result.length = len;
         @in.readBytes(result.bytes, 0, len);
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
 public override long get(int docID)
 {
     try
     {
         //System.out.println(Thread.currentThread().getName() + ": get docID=" + docID + " in=" + in);
         if (docID < 0 || docID >= outerInstance.maxDoc)
         {
             throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID);
         }
         @in.seek(field.dataStartFilePointer + (1 + field.pattern.Length + 2) * docID);
         SimpleTextUtil.ReadLine(@in, scratch);
         //System.out.println("parsing delta: " + scratch.utf8ToString());
         decimal bd;
         try
         {
             bd = (decimal)decoder.parse(scratch.utf8ToString());
         }
         catch (ParseException pe)
         {
             CorruptIndexException e = new CorruptIndexException("failed to parse BigDecimal value (resource=" + @in + ")");
             e.initCause(pe);
             throw e;
         }
         SimpleTextUtil.ReadLine(@in, scratch);       // read the line telling us if its real or not
         return(System.Numerics.BigInteger.valueOf(field.minValue) + (long)bd.toBigIntegerExact());
     }
     catch (IOException ioe)
     {
         throw new Exception(ioe);
     }
 }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRequestIndexPopulationIfTheIndexIsCorrupt()
        internal virtual void ShouldRequestIndexPopulationIfTheIndexIsCorrupt()
        {
            // Given
            long faultyIndexId          = 1;
            CorruptIndexException error = new CorruptIndexException("It's broken.", "");

            LuceneIndexProvider provider = NewFaultyIndexProvider(faultyIndexId, error);

            // When
            StoreIndexDescriptor descriptor   = forSchema(forLabel(1, 1), provider.ProviderDescriptor).withId(faultyIndexId);
            InternalIndexState   initialState = provider.GetInitialState(descriptor);

            // Then
            assertThat(initialState, equalTo(InternalIndexState.POPULATING));
            _logProvider.assertAtLeastOnce(LoggedException(error));
        }
            public override void LookupOrd(long ord, BytesRef result)
            {
                try
                {
                    if (ord < 0 || ord >= _field.NumValues)
                    {
                        throw new IndexOutOfRangeException("ord must be 0 .. " + (_field.NumValues - 1) + "; got " + ord);
                    }

                    _input.Seek(_field.DataStartFilePointer + ord * (9 + _field.Pattern.Length + _field.MaxLength));
                    SimpleTextUtil.ReadLine(_input, _scratch);
                    // LUCENENET specific - use wrapper BytesRefFormatter struct to defer building the string unless string.Format() is called
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH), "got {0} in={1}", new BytesRefFormatter(_scratch, BytesRefFormat.UTF8), _input);
                    }
                    int len;
                    try
                    {
                        // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                        len = int.Parse(Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                                _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length), NumberStyles.Integer, CultureInfo.InvariantCulture);
                    }
                    catch (Exception pe) when(pe.IsParseException())
                    {
                        var e = new CorruptIndexException("failed to parse int length (resource=" + _input + ")", pe);

                        throw e;
                    }

                    result.Bytes  = new byte[len];
                    result.Offset = 0;
                    result.Length = len;
                    _input.ReadBytes(result.Bytes, 0, len);
                }
                catch (Exception ioe) when(ioe.IsIOException())
                {
                    throw RuntimeException.Create(ioe);
                }
            }
            public override void LookupOrd(int ord, BytesRef result)
            {
                try
                {
                    if (ord < 0 || ord >= _field.NumValues)
                    {
                        throw new IndexOutOfRangeException("ord must be 0 .. " + (_field.NumValues - 1) + "; got " +
                                                           ord);
                    }
                    _input.Seek(_field.DataStartFilePointer + ord * (9 + _field.Pattern.Length + _field.MaxLength));
                    SimpleTextUtil.ReadLine(_input, _scratch);
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(StringHelper.StartsWith(_scratch, SimpleTextDocValuesWriter.LENGTH),
                                         () => "got " + _scratch.Utf8ToString() + " in=" + _input);
                    }
                    int len;
                    try
                    {
                        // LUCNENENET: .NET doesn't have a way to specify a pattern with integer, but all of the standard ones are built in.
                        len = int.Parse(Encoding.UTF8.GetString(_scratch.Bytes, _scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                                                _scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length), NumberStyles.Integer, CultureInfo.InvariantCulture);
                    }
                    catch (Exception pe)
                    {
                        var e = new CorruptIndexException("failed to parse int length (resource=" + _input + ")", pe);
                        throw e;
                    }

                    result.Bytes  = new byte[len];
                    result.Offset = 0;
                    result.Length = len;
                    _input.ReadBytes(result.Bytes, 0, len);
                }
                catch (IOException ioe)
                {
                    throw new Exception(ioe.ToString(), ioe);
                }
            }
Exemple #10
0
		private byte[] Uncompress(byte[] b)
		{
			try
			{
				return CompressionTools.Decompress(b);
			}
			catch (Exception e)
			{
				// this will happen if the field is not compressed
				CorruptIndexException newException = new CorruptIndexException("field data are in wrong format: " + e.ToString(), e);
				throw newException;
			}
		}