internet file size?

Discussion in 'Java' started by Marco Schmidt, Jun 28, 2003.

  1. Disintegration:

    >Is there a way to know a file size through a java internet program? Such as
    >first reading the size of an image over the internet on a web page given
    >that image link.


    Some webservers return a content-length HTTP header. But you can't
    count on it being there.

    Regards,
    Marco
    --
    Please reply in the newsgroup, not by email!
    Java programming tips: http://jiu.sourceforge.net/javatips.html
    Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
    Marco Schmidt, Jun 28, 2003
    #1
    1. Advertising

  2. Is there a way to know a file size through a java internet program? Such as
    first reading the size of an image over the internet on a web page given
    that image link.

    thanks
    ray
    Disintegration, Jun 28, 2003
    #2
    1. Advertising

  3. Marco Schmidt

    Jon A. Cruz Guest

    Disintegration wrote:
    > Is there a way to know a file size through a java internet program? Such as
    > first reading the size of an image over the internet on a web page given
    > that image link.



    You mean "over HTTP"?

    Nope.

    Servers are supposed to send the size in the header, but for 1.0 that
    was purely advisory (aka "don't count on this being real").

    However...

    If you have a nice, well behaved server, you could send it an HTTP HEAD
    request to see what it wants to tell you the size is. It's not 'know'
    with the certancy of java.io.File.length(), but is usable as long as you
    don't trust it 100% (i.e. don't statically allocate an array to that
    size and trust you can shove in without checking)
    Jon A. Cruz, Jun 28, 2003
    #3
  4. "Disintegration" <> wrote in message news:3efbb197_1@newsfeed...
    > Is there a way to know a file size through a java internet program? Such

    as
    > first reading the size of an image over the internet on a web page given
    > that image link.
    >
    > thanks
    > ray
    >
    >
    >


    I guess you can have the java program download the image then see how big it
    was.
    Miguel De Anda, Jun 30, 2003
    #4
  5. Marco Schmidt

    Jon A. Cruz Guest

    Phil Hanna wrote:
    > int length = con.getContentLength();
    > System.out.println("Image file size is " + length + " bytes");
    > }
    > }
    >
    > You could fine tune this by opening a socket directly, issuing an HTTP
    > HEAD command, then scanning the response headers for
    > "Content-Length:".


    Remember, especially for HTTP 1.0, that this lenght could be only "advisory"
    Jon A. Cruz, Jul 2, 2003
    #5
  6. Marco Schmidt

    Roedy Green Guest

    On Mon, 30 Jun 2003 22:14:38 GMT, "Miguel De Anda"
    <> wrote or quoted :

    >> first reading the size of an image over the internet on a web page given
    >> that image link.

    If you want to know the width and height, you can read the first few
    bytes and use some logic such is in the ImageInfo class.

    See http://mindprod.com/products.html#BUS

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 5, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tiewknvc9
    Replies:
    6
    Views:
    637
    Chris Uppal
    Oct 1, 2006
  2. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,501
    Michael Jung
    May 25, 2008
  3. Keith Thompson

    Re: File Size - Big File Size

    Keith Thompson, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    274
    Phil Carmody
    Oct 3, 2009
  4. Michael Tsang

    Re: File Size - Big File Size

    Michael Tsang, Oct 4, 2009, in forum: C Programming
    Replies:
    2
    Views:
    305
    Keith Thompson
    Oct 4, 2009
  5. Nobody

    Re: File Size - Big File Size

    Nobody, Oct 5, 2009, in forum: C Programming
    Replies:
    10
    Views:
    1,995
    Flash Gordon
    Oct 10, 2009
Loading...

Share This Page