Changeset 4056


Ignore:
Timestamp:
Dec 12, 2007, 9:35:46 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #873: AbstractFlatFileImporter? should use number of parsed bytes for progress reporting

Location:
branches/2.5-stable/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5-stable/src/core/net/sf/basedb/util/parser/FlatFileParser.java

    r4020 r4056  
    4747import net.sf.basedb.core.BaseException;
    4848import net.sf.basedb.core.Config;
     49import net.sf.basedb.util.InputStreamTracker;
    4950
    5051/**
     
    176177
    177178  /**
     179    For keeping track of the number of bytes parsed.
     180  */
     181  private InputStreamTracker tracker;
     182 
     183  /**
    178184    The regular expression for matching a header line.
    179185  */
     
    522528  {
    523529    Charset cs = Charset.forName(charsetName == null ? Config.getCharset() : charsetName);
    524     this.reader = new BufferedReader(new InputStreamReader(in, cs));
     530    this.tracker = new InputStreamTracker(in);
     531    this.reader = new BufferedReader(new InputStreamReader(tracker, cs));
    525532  }
    526533
     
    11161123    correspond to the number of parsed bytes depending on the character
    11171124    set of the file.
     1125    @see #getParsedBytes()
    11181126  */
    11191127  public long getParsedCharacters()
    11201128  {
    11211129    return parsedCharacters;
     1130  }
     1131 
     1132  /**
     1133    Get the number of parsed bytes so far. This value may or may not
     1134    correspond to the number of parsed characters depending on the character
     1135    set of the file.
     1136    @since 2.5.1
     1137    @see #getParsedCharacters()
     1138  */
     1139  public long getParsedBytes()
     1140  {
     1141    return tracker == null ? 0 : tracker.getNumRead();
    11221142  }
    11231143 
  • branches/2.5-stable/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r3889 r4056  
    536536        if (section != null && section.type() == FlatFileParser.LineType.SECTION)
    537537        {
    538           if (progress != null) progress.display(getProgress(ffp.getParsedCharacters()), "Parsing section "+section.name()+"...");
     538          if (progress != null) progress.display(getProgress(ffp), "Parsing section "+section.name()+"...");
    539539          try
    540540          {
     
    565565        else
    566566        {
    567           if (progress != null) progress.display(getProgress(ffp.getParsedCharacters()), "Parsing headers...");
     567          if (progress != null) progress.display(getProgress(ffp), "Parsing headers...");
    568568        }
    569569        FlatFileParser.LineType result = ffp.parseHeaders();
     
    603603            " on line " + (line == null ? "-1" : line.lineNo() + ": " + StringUtil.trimString(line.line(), 20)), t);     
    604604        }
    605         if (progress != null) progress.display(getProgress(ffp.getParsedCharacters()), "Parsing data...");
     605        if (progress != null) progress.display(getProgress(ffp), "Parsing data...");
    606606        int progressLine = 0;
    607607       
     
    634634              if (progress != null)
    635635              {
    636                 progress.display(getProgress(ffp.getParsedCharacters()), "Parsing data... (" + ffp.getParsedLines() + " lines so far)");
     636                progress.display(getProgress(ffp), "Parsing data... (" + ffp.getParsedLines() + " lines so far)");
    637637              }
    638638            }
     
    662662  // -------------------------------------------
    663663
    664   private int getProgress(long parsedCharacters)
    665   {
    666     return (int) (100 * parsedCharacters / fileSize);
     664  private int getProgress(FlatFileParser ffp)
     665  {
     666    return (int) (100 * ffp.getParsedBytes() / fileSize);
    667667  }
    668668
Note: See TracChangeset for help on using the changeset viewer.