Changeset 7168


Ignore:
Timestamp:
Jun 8, 2016, 1:07:43 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2017: Improve progress reporting in "Packed file exporter" plug-in

We can't send a progress reporter to the packer implementation without breaking the API. Instead we use the ProgressInputStream for wrapping the stream and reporting the progress at the same time as reading data from the source file.

Location:
trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/Values.java

    r6898 r7168  
    601601  }
    602602
    603   private static final long GB = 1073741824;
    604   private static final long MB = 1048576;
    605   private static final long kB = 1024;
     603  public static final long GB = 1073741824;
     604  public static final long MB = 1048576;
     605  public static final long kB = 1024;
    606606 
    607607  /**
  • trunk/src/plugins/core/net/sf/basedb/plugins/PackedFileExporter.java

    r6520 r7168  
    4242import net.sf.basedb.core.ProgressReporter;
    4343import net.sf.basedb.core.RequestInformation;
     44import net.sf.basedb.core.SimpleAbsoluteProgressReporter;
    4445import net.sf.basedb.core.StringParameterType;
    4546import net.sf.basedb.core.Job.ExecutionTime;
     
    5657import net.sf.basedb.core.signal.SignalTarget;
    5758import net.sf.basedb.core.signal.ThreadSignalHandler;
     59import net.sf.basedb.util.ChainedProgressReporter;
    5860import net.sf.basedb.util.FileUtil;
     61import net.sf.basedb.util.ProgressInputStream;
    5962import net.sf.basedb.util.Values;
    6063import net.sf.basedb.util.zip.FilePacker;
     
    357360    FilePacker packer = getPacker();
    358361
     362    ChainedProgressReporter chained = null;
    359363    if (progress != null)
    360364    {
    361365      progress.display(0, "Checking selected files and directories...");
     366      chained = new ChainedProgressReporter(progress);
    362367    }
    363368   
     
    414419            currentFile + " of " + numFiles + " file(s) (" +
    415420            Values.formatBytes(completedBytes) + " of " + Values.formatBytes(totalBytes) + ")");
     421         
     422          if (in != null && size > Values.MB)
     423          {
     424            // Wrap in ProgressInputStream so we get progress reporting while the packer is working
     425            chained.setRange(percent, (int)((size+completedBytes)*progressFactor));
     426
     427            // Progress message template '@' is replaced with actual bytes read
     428            final String msgTemplate =
     429              "Compressing '" + entryPath + "' (@ of " + Values.formatBytes(size) + ")";
     430           
     431            in = new ProgressInputStream(in, new SimpleAbsoluteProgressReporter(chained, size))
     432              {
     433                @Override
     434                protected void progressReport(String msg)
     435                {
     436                  super.progressReport(msgTemplate.replace("@", msg));
     437                }
     438              };
     439          }
    416440        }
    417441 
Note: See TracChangeset for help on using the changeset viewer.