top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can I measure the file downloading time using servlets?

+2 votes
453 views
How can I measure the file downloading time using servlets?
posted Dec 9, 2015 by Joy Nelson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
           ServletOutputStream out = response.getOutputStream();
           String filename = getServletContext().getRealPath(request.getQueryString());
           FileInputStream fin = new FileInputStream(filename);
           long start = System.currentTimeMillis();
           byte data[] = new byte[1024];
           int len = 0;
           while ((len = fin.read(data)) > 0) {
              out.write(data, 0, len);
           }
           out.flush();
           long stop = System.currentTimeMills();
           log("took " + (stop - start) + "ms to download " + filename);
answer Dec 11, 2015 by Karthick.c
...