• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

remote file retrieval

I'm currently using the jakarta httpclient class to download remote files from a webserver.  If all I'm doing is a simple file download...I don't need to support redirects, deal with proxies, etc.  For instance in an applet, I can getImage() from a remote URL with no trouble at all.  This is a swing app...and the file I'm retrieving is not an image, but is there a simple method to get a binary file which is simpler than using the 3rd party library.

I would like to remove my dependence on the library to make deployment a little easier.

Thanks,
David
0
lomidien
Asked:
lomidien
  • 9
  • 7
  • 2
1 Solution
 
CEHJCommented:
Yes if you put the file on the webserver you can read it from the url:

URL url = new URL("http://www.someweb.com/public/file.doc");
URLConnection conn = url.openConnection();
InputStream in = conn.openStream();
// now read it
0
 
lomidienAuthor Commented:
CEHJ,

You make me a bit lazy I think....I need to break that habit.  :)  Thanks for the help!

Thanks,
David
0
 
lomidienAuthor Commented:
most of the problem is that i'm overseas right now...visiting uzbekstan and my internet connection is sooo horrible that it is VERY difficult for me to google for tips.  :(
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
LOL

:-)
0
 
CEHJCommented:
(LOL was to your first comment ;-))
0
 
aozarovCommented:
>> InputStream in = conn.openStream();
InputStream in = conn.getInputStream();

But for a simple http get command the above can be even shorter:
URL url = new URL("http://www.someweb.com/public/file.doc");
InputStream in = url.openStream();
0
 
CEHJCommented:
For any professional solution, you would need to use the URLConnection. e.g. you wouldn't want to download the file irrespective of the fact that it may fit on your HD would you? In order to do that, you'd need to look at the content length
0
 
aozarovCommented:
>>  In order to do that, you'd need to look at the content length
Not always available (but probably will be available for static content).
0
 
CEHJCommented:
>>will be available for static content

(which is the content of interest ;-))
0
 
aozarovCommented:
>> (which is the content of interest ;-))
Right but for this "content of interest" using directly URL would be sufficient.
0
 
CEHJCommented:
>>Right but for this "content of interest" using directly URL would be sufficient.

That would depend on the degree of professionalism of the app. For a quick-and-dirty approach, then i'd agree
0
 
aozarovCommented:
>> That would depend on the degree of professionalism of the app. For a quick-and-dirty approach, then i'd agree
For loading the application images or for any case where your only interaction with URLConnection is getInputStream (which is exactly what URL.openStream does) that should be fine.
0
 
CEHJCommented:
>>... your only interaction with URLConnection is getInputStream

The point is - that *wouldn't* be your only interaction in an application *of a professional standard*
0
 
aozarovCommented:
>> The point is - that *wouldn't* be your only interaction in an application *of a professional standard*
With that I don't agree. Using a small subset of features of any given functionality (like URL/URLConnection) does not make your application unprofessional.
You only should use what you need and for loading your application images calling openStream on your URL is sufficient.
0
 
CEHJCommented:
Well i'm glad you're not writing apps that access my HD then ;-)
0
 
aozarovCommented:
>> Well i'm glad you're not writing apps that access my HD then ;-)
1. Are you seriously thinking that loading an Icon/image for an application by calling openStream would have any significant effect on your HD?
2. Your original advice (which was syntactically wrong) mentioned nothing about "Content-Length" or any other usage of URLConnection which is better then calling
directly to URL#openStream:
>> InputStream in = conn.openStream();
>> // now read it
3. How do you know that you are not running any of my apps ;-)
0
 
CEHJCommented:
>>1. Are you seriously thinking that loading an Icon/image for an application by calling openStream would have any significant effect on your HD?

Firstly, what makes you think it's anything to do with an image? Secondly i  certainly wouldn't want an application loading a file irrespective of its size onto my machine
0
 
aozarovCommented:
>> Firstly, what makes you think it's anything to do with an image?
He actually mention that it is not an image but he also mention this, "For instance in an applet, I can getImage()", as an equavelent loading style.

>> Secondly i  certainly wouldn't want an application loading a file irrespective of its size onto my machine
If that case (which I don't agree with [the part "irrespective of its size" when talking about files that you know]) then providing this information as part of the answer would be helpful.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now