struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dakota Jack <dakota.j...@gmail.com>
Subject Re: DownloadAction Application
Date Mon, 07 Mar 2005 19:52:02 GMT
Yes, this is possible and an interface for doing that is given my my
presentation on the wiki.  If you look at the classes and where
(Monitor)iter.next() occurs in the UploadFileItem class, etc. you will
see how to implement such monitors generally.  If you are interested,
the implementation I use to monitor the upload is:

public class UploadMonitorProgress
    implements Monitor {
  private           File        tempFile        = null;
  private           boolean     uploaded        = false;
  private           boolean     cancelled       = false;
  private           int         accumulatedSize = -1;
  private           int         size            = -1;
  private           int         totalSize       = -1;
  private           int         fileNumber      = 0;

  public UploadMonitorProgress() {
  }

  public void init(File   tempFile,
                   int    totalSize,
                   String contentType) {
    this.tempFile  = tempFile;
    this.totalSize = totalSize;
    this.uploaded  = false;
    this.cancelled = false;
    this.size      = 0;
    this.fileNumber++;
  }

  public void notify(UploadParams up,
                     MultipartFile file) {
    uploaded = true;
  }

  public void read(int read) {
    size            += read;
    accumulatedSize += read;
  }

  public boolean isFileUploaded() {
    return uploaded;
  }

  public boolean isFileUploadCancelled() {
    return cancelled;
  }

  public int getUploadedKBLength() {
    int kbLength = Math.round(size * 1.0f / 1024.0f);
    return kbLength;
  }

  public int getUploadedLength() {
    return size;
  }

  public int getFileUploadedRatio() {
    if (totalSize > 0) {
      int ratio = (int) Math.round(accumulatedSize * 100.0f / totalSize * 1.0f);
      return ratio;
    } else {
      return 0;
    }
  }

  public int getTotalUploadedRatio() {
    if (totalSize > 0) {
      int ratio = (int) Math.round(accumulatedSize * 100.0f / totalSize * 1.0f);
      return ratio;
    } else {
      return 0;
    }
  }

  public int getFileNumber() {
    return fileNumber;
  }

  public int getAccumulatedSize() {
    return accumulatedSize;
  }

  public int getTotalLength() {
    return totalSize;
  }

  public void cancel() {
    this.cancelled = true;
  }

  public void reset() {
    cleanLastUpload();
    tempFile        = null;
    totalSize       = -1;
    uploaded        = false;
    cancelled       = false;
    size            = -1;
    accumulatedSize = -1;
    fileNumber      = 0;
  }

  public void cleanLastUpload() {
     if (tempFile != null) {
       String tmpFileName = tempFile.getName();
       tempFile.delete();
     }
  }
}

Does this help?

On Mon, 7 Mar 2005 19:37:41 +0100, Leon Rosenberg
<struts_user@anotheria.net> wrote:
> <2cents>

> Another nice feature would be a monitor, which can inform the client about
> current progress,
> like in a javascript application.
> 
> I'm not sure whether the first is possible with the current jsp/servlet
> spec, but the second feature
> should be possible, and is very useful.
> </2cents>
> 
> Regards
> Leon
> 
> > -----Ursprüngliche Nachricht-----
> > Von: Dakota Jack [mailto:dakota.jack@gmail.com]
> > Gesendet: Montag, 7. März 2005 17:47
> > An: Struts Users Mailing List
> > Betreff: DownloadAction Application
> >
> > I am presently beginning to code a download application to go
> > with my upload application
> > (http://wiki.apache.org/struts/StrutsUpload) in Struts,
> > although I am not initially trying to combine them.  That
> > will be a part of refactoring.  Does anyone have any code or
> > ideas out there they would suggest is the "cat's meow" on
> > this?  Any "gotchas"
> > that need to be watched?
> >
> > Thanks!
> >
> > Jack
> >
> > --
> > "You can lead a horse to water but you cannot make it float
> > on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message