This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes parsing inputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "parsing inputStream" Watch "parsing inputStream" New topic
Author

parsing inputStream

kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
i'm writing a small program to that connects to a URL and reads it

e.g

//...

URL yahoo new URL("http://yahoo.com/");
URLConenection yc = yahoo.openConnection();
BufferedReader in new BufferedReader(new InputStreamReader(yc.getInputStream()));

//...more code to readLine and then print etc

can someone please tell me of a method in java.net or otherwise, that could be used to get a certain type of information from an input stream say a certain link or a some known string, instead of just the whole page!!!

thanks
[ October 11, 2005: Message edited by: kwame Iwegbue ]

Who dares, wins! (SAS motto)
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Depends on what the "certain type of information" is and what the contents of the input stream is. For example if the content of the stream is a gif file, what would you want to get?
Please describe the input data?
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
say i want to get only a particular string of text from the page, or only a particular link which is already known to me, so that i can print only that string of text or maybe even follow only that link from the page...

[ October 11, 2005: Message edited by: kwame Iwegbue ]
[ October 11, 2005: Message edited by: kwame Iwegbue ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Depending on the complexity of the parsing you want to do, you can use IntputStreamTokenizer, classes in java.util.regex, or a full blown parser such as javacc. No matter which of these you choose, you will ened up reading the complete content of the InputStream (or close to it).

Layne


Java API Documentation
The Java Tutorial
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
You should probably google for an open source Java html parser...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
kwame Iwegbue
Ranch Hand

Joined: Sep 02, 2000
Posts: 197
Thanks for your suggestions. They were quite useful. Does anyone know where to find tutorials on 'parsing HTML" I've done a google search, but it seems only one article at java.sun came close to what I need. it was addressing Swing HTML parser. but can I find more articles? specifically, I'm trying to parse out text from a html file
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You can find an HTML parser here: http://htmlparser.sourceforge.net/


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: parsing inputStream
 
Similar Threads
URL Harvester
Writing a file from an Applet
Directory structure & getResource() problems
scanning the webpage
What is the purpose of using this command?