Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Univocity解析器-如何在已解析的bean中获取行号_Java_Parsing_Univocity - Fatal编程技术网

Java Univocity解析器-如何在已解析的bean中获取行号

Java Univocity解析器-如何在已解析的bean中获取行号,java,parsing,univocity,Java,Parsing,Univocity,使用UnivocityFixedWidthParser时,如何将记录/行号添加为解析bean中的字段 是否有一个选项可以将bean属性标记为记录号,如: 我使用的是InputValueSwitch。是否有一种方法可以在rowProcessorSwitched()中获取上下文,以便我可以尝试: 在rowProcessorSwitched()中,像 long lineNumber = refToContext.currentLine() - 1; 这是一种有效的方法吗?当解析过程中遇到错误时,它是

使用Univocity
FixedWidthParser
时,如何将记录/行号添加为解析bean中的字段

  • 是否有一个选项可以将bean属性标记为记录号,如:
  • 我使用的是
    InputValueSwitch
    。是否有一种方法可以在
    rowProcessorSwitched()
    中获取上下文,以便我可以尝试:
  • 在rowProcessorSwitched()中,像

    long lineNumber = refToContext.currentLine() - 1;
    
    这是一种有效的方法吗?当解析过程中遇到错误时,它是否可靠

    final BeanListProcessor<MyRecord> myProcessor = new BeanListProcessor<MyRecord>(
                        MyRecord.class);
    
    public void rowProcessorSwitched(RowProcessor from, RowProcessor to) {
        ParsingContext context = ... //how to get this?
        long lineNumber = context.currentLine(); //if i can get this...
        if (from == myProcessor){
          (MyRecord)myProcessor.getBeans().get(0).setRecordNumber(lineNumber); //...then this should be possible
          //other switch logic
        }
    } 
    
       ParsingContext refToContext = null;
       
       public void processStarted(ParsingContext context) {
         refToContext = context;
         super.processStarted(context);
      } 
    
    long lineNumber = refToContext.currentLine() - 1;