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 void LookupOrd(long ord, BytesRef result)
            {
                if (ord < 0 || ord >= field.NumValues)
                {
                    throw new 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, SimpleTextDocValuesWriter.LENGTH),
                             "got " + scratch.Utf8ToString() + " in=" + @in);
                int len;

                try
                {
                    len =
                        (int)
                        decoder.parse(scratch.Bytes.SubList(
                                          scratch.Offset + SimpleTextDocValuesWriter.LENGTH.Length,
                                          scratch.Length - SimpleTextDocValuesWriter.LENGTH.Length).ToString());
                }
                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);
            }
 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 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);
     }
 }
Beispiel #7
0
        /**
         * "Parse" an XML document for the first occurrence of a particular tag and return its value, which is assumed to be a number.
         *
         * The parse terminates based on the rules for java.text.DecimalFormat, using the
         * pattern and symbol sets for the default Locale.
         *
         * @param xmlDoc
         *  The target XML document.
         * @param xmlTag
         *  The target tag <em>including</em> the enclosing angle brackets.
         * @param xmlStart
         *  The character position (from zero) in the document at which to start
         *  looking for the target tag.
         *
         * @return
         *  <ul>
         *      <li>an integer representation of the element value</li>
         *      <li>-1 if:
         *          <ul>
         *              <li>not found</li>
         *              <li>the target tag is empty, for example, <code>&lt;part&gt;&lt;/part&gt;</code></li>
         *              <li>a parse error occurred</li>
         *          </ul>
         *      </li>
         *  </ul>
         *
         * @since 1.0
         */
        public int getXmlValueNum(String xmlDoc, String xmlTag, ParsePosition xmlStart)
        {
            if (verboseDebugLvl)
            {
                MySession.myConsole.printf("%s.getXmlValueNum: xmlDoc =%n%s%nxmlTag = %s%nstartIdx = %d%n",
                                           MY_CLASS_TAG, xmlDoc, xmlTag, xmlStart.getIndex());
            }

            parseFmt.setParseBigDecimal(false);
            parsePos.setErrorIndex(-1);

            int i = xmlDoc.IndexOf(xmlTag, xmlStart.getIndex());

            if (i != -1)
            {
                parsePos.setIndex((i + xmlTag.Length));
                if ((parseResult = parseFmt.parse(xmlDoc, parsePos)) != null)
                {
                    return(parseResult.intValue());
                }
            }
            return(-1);
        }