Changeset 4101


Ignore:
Timestamp:
Jan 28, 2008, 11:02:08 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #904: Subclasses of AbstractFlatFileImporter? should be able to wrap the file inputstream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r4095 r4101  
    500500  {
    501501    FlatFileParser ffp = getInitializedFlatFileParser();
    502     ffp.setInputStream(in, getCharset());
    503502    ffp.setDefaultNumberFormat(getNumberFormat());
    504503    try
    505504    {
     505      in = wrapInputStream(in);
     506      ffp.setInputStream(in, getCharset());
    506507      ffp.nextSection();
    507508      FlatFileParser.LineType result = ffp.parseHeaders();
     
    527528    FlatFileParser ffp = getInitializedFlatFileParser();
    528529    FlatFileParser.Data dataline = null;
    529     ffp.setInputStream(in, getCharset());
    530530    ffp.setDefaultNumberFormat(getNumberFormat());
    531531    boolean useNullIfException = "null".equals(job != null ? job.getValue("numberFormatError") : "");
     
    534534    try
    535535    {
     536      in = wrapInputStream(in);
     537      ffp.setInputStream(in, getCharset());
    536538      skippedLines = 0;
    537539      begin(ffp);
     
    685687  // -------------------------------------------
    686688
    687   private int getProgress(FlatFileParser ffp)
    688   {
    689     return (int) (100 * ffp.getParsedBytes() / fileSize);
     689  /**
     690    Get the progress of import as a percentage value. The default implementation
     691    calls {@link #getNumBytes(FlatFileParser)} and divides it by the file size.
     692    @param ffp The file parser that is used to parsed the file
     693    @return A value between 0 and 100
     694    @since 2.6
     695  */
     696  protected int getProgress(FlatFileParser ffp)
     697  {
     698    return (int) (100 * getNumBytes(ffp) / fileSize);
     699  }
     700 
     701 
     702  /**
     703    Get the number of bytes read from the file. The value should indicate the
     704    how far into the file parsing has proceeded. The default
     705    implementation calls {@link FlatFileParser#getParsedBytes()}. If a subclass has
     706    wrapped the input stream the number of parsed byts may not correspond to the
     707    number of bytes read from the file.
     708    For example, if the file is a compressed file the number of parsed bytes will
     709    be higher than the number of bytes read from the file.
     710    @param ffp The file parser that is used to parsed the file
     711    @return The number of bytes read from the original file
     712    @see #wrapInputStream(InputStream)
     713    @see #getProgress(FlatFileParser)
     714    @since 2.6
     715  */
     716  protected long getNumBytes(FlatFileParser ffp)
     717  {
     718    return ffp.getParsedBytes();
    690719  }
    691720
     
    705734  {
    706735    return true;
     736  }
     737 
     738  /**
     739    This method is called before the parser starts reading from the
     740    input stream. A subclass may override this method to wrap the inputstream
     741    with a filtering stream, for example, a gzip input stream. The default
     742    implementation of this method returns the original stream unmodified. If a subclass
     743    overrides this methods it may also need to override one of the
     744    {@link #getNumBytes(FlatFileParser)} or {@link #getProgress(FlatFileParser)}
     745    methods.
     746    @param in The input stream to wrap
     747    @return The same or a different input stream
     748    @since 2.6
     749    @see #getNumBytes(FlatFileParser)
     750  */
     751  protected InputStream wrapInputStream(InputStream in)
     752    throws IOException
     753  {
     754    return in;
    707755  }
    708756 
Note: See TracChangeset for help on using the changeset viewer.