473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Count number of bytes downloaded

Hi

I want to know how we can keep track of number bytes downloaded at client side.
I want to make a program that will keep track of number of bytes downloaded
after downloading is completed.
Also, if user cancel the downloading then also it should stored the number of bytes downloaded at client side so that I can resume downloading when client will ask for downloading
Sep 11 '07 #1
4 2513
Nepomuk
3,112 Expert 2GB
Hi

I want to know how we can keep track of number bytes downloaded at client side.
I want to make a program that will keep track of number of bytes downloaded
after downloading is completed.
Also, if user cancel the downloading then also it should stored the number of bytes downloaded at client side so that I can resume downloading when client will ask for downloading
How do you download those bytes? With a Socket? A URLConnection? FTP? You'll have to give us more information, so that we can help you.

Greetings,
Nepomuk
Sep 11 '07 #2
Actually I want it using URL so that I can include this in any web page
Sep 11 '07 #3
Nepomuk
3,112 Expert 2GB
Actually I want it using URL so that I can include this in any web page
It depends. If you only want to download from a source that runs a servlet written by you, you'll have to download packages of bytes (e.g. an Array of 1024 Bytes) one by one and count, how many packages you've downloaded. Of course for that, the servlet must offer the packages one by one.

If however you want to download from any source you chose, you have a problem, as I don't think there is any URL class (at least no standard one) with such a function preimplemented.

I can't think of anything else right now, maybe someone else has a better idea? (Or can correct me, if I'm wrong?)

Greetings,
Nepomuk
Sep 11 '07 #4
JosAH
11,448 Expert 8TB
I can't think of anything else right now, maybe someone else has a better idea? (Or can correct me, if I'm wrong?)

Greetings,
Nepomuk
Be lazy and think wrappers/decorators; at the end an InputStream is used;
here's the CountingInputStream wrapper class:

Expand|Select|Wrap|Line Numbers
  1. public class CountingInputStream extends InputStream {
  2.    protected long count;
  3.    private InputStream is;
  4.    public CountedInputStream(InputStream is) { this.is= is; }
  5.    public long getCount() { return count; }
  6.    public int read() throws IOException {
  7.       int i= is.read();
  8.       if (i >= 0) count++;
  9.       return i;
  10.    }
  11. }
  12.  
That's all you need; wrap the real InputStream in this thingy, use it for reading and
let it count for you.

Note that I made the 'count' member protected just in case someone gets
enthousiastic and wants to build a ResetableCountingInputStream ;-)

kind regards,

Jos
Sep 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
1
by: Oleg Ogurok | last post by:
Hi all, I have a page that's long (>400kb) and therefore takes several seconds to download. I want to put either a progress bar or a simple counter that would show how many percent of the page...
2
by: Joe | last post by:
I'm trying to get the location of the image uisng start = s.find('<a href="somefile') + len('<a href="somefile') stop = s.find('">Save File</a></B>', start) fileName = s and then construct the...
4
by: Jofio | last post by:
I am developing a picture gallery - pictures of landscapes and various other subjects. My site has a left panel consisting of thumbnails of pictures which when clicked displays the corresponding...
2
by: willie | last post by:
John Machin: Thank you for your patience and for educating me. (Though I still have a long way to go before enlightenment) I thought Python might have a small weakness in lacking an...
1
by: Proogeren | last post by:
Hello I was wondering how I can make query on 3 tables and sort on a count statement E.g If I have one table Person I have one table Movie I have one table Downloaded If a person download...
4
by: Proogeren | last post by:
Hello I have the following query SELECT COUNT(ur.resourceId) AS times_downloaded FROM Resource as r, user_resource as ur WHERE r.resourceId = ur.resourceId Group BY ur.resourceId
9
by: salil123 | last post by:
How we can keep track of number of bytes downloaded at client side using PHP?. or user has canceled the downloading? so that downloaded bytes can be entered in database can you give me the...
0
by: salil123 | last post by:
Hi I want to know how we can keep track of number bytes downloaded at client side. I want to make a program that will keep track of number of bytes downloaded after downloading is completed....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.