Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   compare file size with online file size (http://www.velocityreviews.com/forums/t373831-compare-file-size-with-online-file-size.html)

tiewknvc9 09-30-2006 01:22 AM

compare file size with online file size
 
hi!

Im trying to make something that compares 2 files. One of the files is
on the users computer....

The other is on a website!

Obviously what Im trying to do is compare the lastModified date, in
order to update the file on the users computer if neccessary.

Only problem is that I dont know how I can get the size of the file
online without downloading it first...

Any ideas?


Nick Vatamaniuc 09-30-2006 02:55 AM

Re: compare file size with online file size
 
Would the HTTP "Content-length" header line help you? Some servers
don't send that so sometime you wouldn't know ahead of time. But in
general you can use the urllib module and then the info() method of the
urllib.urlopen() handler.

Here is the magic:

------------------------------------
In [1]: import urllib

In [2]:
hand=urllib.urlopen('http://www.python.org/images/python-logo.gif')

In [3]: hand.info().dict['content-length']
Out[3]: '2549'
-------------------------------------

Cheers,
-Nick V.


tiewknvc9 wrote:
> hi!
>
> Im trying to make something that compares 2 files. One of the files is
> on the users computer....
>
> The other is on a website!
>
> Obviously what Im trying to do is compare the lastModified date, in
> order to update the file on the users computer if neccessary.
>
> Only problem is that I dont know how I can get the size of the file
> online without downloading it first...
>
> Any ideas?



Andrew Thompson 09-30-2006 03:12 AM

Re: compare file size with online file size
 
tiewknvc9 wrote:
...
>....in
> order to update the file on the users computer if neccessary.


WebStart can handle that (for data files, as well as classes)
for the user automatically and relatively painlessly - with a
progress dialog.

Andrew T.


tiewknvc9 09-30-2006 05:49 AM

Re: compare file size with online file size
 
unfortunately Im trying to avoid webstart (I dont like the whole code
signing thing)

So I created a class... something like this to compare the file sizes

//get online file size
URL url;
URLConnection conn;
long lSizeOfOnlineFile = 0;
long lSizeClientFile = filClientFile.length();
System.out.println("\nSize of Client file: " + lSizeClientFile + "
" + filClientFile.getAbsolutePath());
try {
url = new URL(strRemoteFile);
conn = url.openConnection();
lSizeOfOnlineFile = conn.getContentLength();
if(lSizeOfOnlineFile < 0){
System.out.println("Could not determine file size.");
}else{
System.out.println("\nSize of Online file: " +
lSizeOfOnlineFile);
}
conn.getInputStream().close();
}
catch(Exception e) {
e.printStackTrace();
}

//compare and act if files modification date are different
if (filClientFile == null){
System.out.println("filClientFile = null");
}

if (lSizeOfOnlineFile != lSizeClientFile){



Andrew Thompson wrote:
> tiewknvc9 wrote:
> ..
> >....in
> > order to update the file on the users computer if neccessary.

>
> WebStart can handle that (for data files, as well as classes)
> for the user automatically and relatively painlessly - with a
> progress dialog.
>
> Andrew T.



Andrew Thompson 09-30-2006 07:15 AM

Re: compare file size with online file size
 
tiewknvc9 wrote:

Please refrain from top-posting.

> unfortunately Im trying to avoid webstart (I dont like the whole code
> signing thing)


WebStart applications do *not* need to be signed if ..
- they don't require a 'trusted environment'
- (or) they use the inbuilt JNLP API to access things
like files, clipboard and printer.

Re engineering a normal 'full access' application to
work within the JNLP API's can be tricky, but is
worth investigating.

Andrew T.


Simon Brooke 10-01-2006 07:34 AM

Re: compare file size with online file size
 
in message <1159579333.616719.27290@b28g2000cwb.googlegroups. com>,
tiewknvc9 ('aotemp@hotmail.com') wrote:

> hi!
>
> Im trying to make something that compares 2 files. One of the files is
> on the users computer....
>
> The other is on a website!
>
> Obviously what Im trying to do is compare the lastModified date, in
> order to update the file on the users computer if neccessary.
>
> Only problem is that I dont know how I can get the size of the file
> online without downloading it first...
>
> Any ideas?


HTTP head request will get you the size and last changed date without
pulling the whole file.

--
simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/
Wannabe a Web designer?
<URL:http://userfriendly.org/cartoons/archives/97dec/19971206.html>


Chris Uppal 10-01-2006 09:30 AM

Re: compare file size with online file size
 
Simon Brooke wrote:

> HTTP head request will get you the size and last changed date without
> pulling the whole file.


And sometimes the server actually obeys the HTTP spec and sends back the
correct information...

-- chris

(Actually, they often do -- but it's not something to rely on)




All times are GMT. The time now is 02:44 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.