Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Searching an input buffer

Thread view: 
Alan - 03 Oct 2007 12:24 GMT
Is there an easy way to search a BufferedInputStream for
occurrence of a string?

    I am reading web pages into the stream and wanted to search them
for the occurrence of URLs and certain HTML tags in them.  This data
can span multiple lines.

    I am new to Java.  If there is a better way to accomplish this, I
am open to suggestions.

                         Thanks, Alan
Chris - 04 Oct 2007 03:51 GMT
>     Is there an easy way to search a BufferedInputStream for
> occurrence of a string?
[quoted text clipped - 7 lines]
>
>                           Thanks, Alan

There are multiple ways to do it. First, you have wrap the InputStream
in a Reader (an InputStreamReader will do), to convert the bytes to chars.

Once you've done this, you can:

1. Read the whole page into a String and use regular expresions on it.
See java.util.regex.

2. Use a more flexible package like JFlex (http://jflex.de). JFlex is
super powerful and super fast, but there is a learning curve. It's what
I use for this purpose.

3. Use one of the HTML parsers out there, like JTidy or NekoHTML.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.