⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadoutputstreamlistener.java

📁 一个视频网站的源码
💻 JAVA
字号:
package com.puckasoft.video312.upload;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;

public class UploadOutputStreamListener implements OutputStreamListener
{
  private HttpServletRequest request;
  private long delay = 0;
  private long startTime = 0;
  private int totalToRead = 0;
  private int totalBytesRead = 0;
  private int totalFiles = -1;

  public UploadOutputStreamListener(HttpServletRequest request, long debugDelay)
  {
    this.request = request;
    this.delay = debugDelay;
    totalToRead = request.getContentLength();
    this.startTime = System.currentTimeMillis();
  }

  public void start()
  {
    totalFiles ++;
    updateUploadInfo("start");
  }

  public void bytesRead(int bytesRead)
  {
    totalBytesRead = totalBytesRead + bytesRead;
    updateUploadInfo("progress");

    try
    {
      if(delay>0)
      {
        Thread.sleep(delay);
      }
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
  }

  public void error(String message)
  {
    updateUploadInfo("error");
  }

  public void done()
  {
    updateUploadInfo("done");
  }

  private long getDelta()
  {
    return (System.currentTimeMillis() - startTime) / 1000;
  }

  private void updateUploadInfo(String status)
  {
    long delta = (System.currentTimeMillis() - startTime) / 1000;
    request.getSession().setAttribute("uploadInfo", new UploadInfo(totalFiles, totalToRead, totalBytesRead,delta,status));
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -