aspose file tools
The moose likes Java in General and the fly likes inputStream openStream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "inputStream openStream" Watch "inputStream openStream" New topic
Author

inputStream openStream

ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
Hello Java friends,

I am struggling here with an issue which I couldn't figure out how to handle. Basically I am sending queries to google and returning links and then opening streams to each of these urls.

Here is my UrlReader class:




the problem I am having is some urls are not responding or basically have 404 and when it happens my application stops running and quit with the message of forexample:



what I want to do is build some kind of timer or a flag and if the connection fails or simply if the server doesn't respond I want my program to silently keep on crawling through the rest of the list of URLs.

What kind of way should I follow interms of that? I'd be grateful if you guys point me out the approach I should take here.


my best
ilteris
ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
is this a bad question to ask in this section?

thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

There's no way to know if a URL is bad until you try to open it. The immediate problem here is that if you find a bad URL and catch an exception, you return a null InputStream; then the "readContent" method tries to open a BufferedReader on that null stream, you get a NullPointerException, and the program aborts. If you catch an exception while opening a URL, don't continue trying to read it -- move on to the next one. The readContent() method could simply check for those nulls.


[Jess in Action][AskingGoodQuestions]
ilteris kaplan
Ranch Hand

Joined: Jan 21, 2006
Posts: 38
thanks for the heads up! adding an if-clause did the trick.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inputStream openStream
 
Similar Threads
street music
regex confusion.
how to resolve UnknownHostException:
Servers down? Pants too?
Happy Norooz (New Year) at JavaRanch