• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ignoring alternate Paragraph from an Input Stream

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
I am getting an FileInputStream which contains
few paragraphs of data, i like to read only alternate paragraphs. my paragraphs should be in
input stream only (because my application can process only streams not readers).
so how can i mark an empty line in the input
stream and how could i ignore the few lines from
the input stream.
Thanks
Regards
Chandhrasekar Saravanan
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you've got an InputStream, you will probably need to read all the bytes from the stream. However after you read them you can decide to ignore some of them if you like. What do you want to do with the paragraphs you don't ignore?
What do different paragraphs look like in your input stream? Are they separated by multiple newlines (\n)? Or maybe HTML tags like <p> and </p>? Or something else? There are several possibilities here, so you need to understand the nature of your input data before deciding on a strategy for interpreting it.
 
Chandhrasekar Saravanan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Jim,
Thanks for your reply. sorry i havent given
you enough information.
I am trying to develop somewhat like an input
stream filter, where the incoming input stream contains many paragraphs and the paragraphs are separated by "\n" charecter.
my filter should read all the input stream
from the incoming streams and it must filter only
the required paragraphs and should just "ignore"
the remaining paragraphs. and pass the result
as an another input stream to my application.
how could we recognize a new line charecter
such as "\n" in an byte input stream. and how could we ignore the contents following them
Thanks
Reagards
Chandhrasekar Saravanan
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you talking about implementing a FilterInputStream (or perhaps FilterReader)?
And when you look at a given paragraph - how do you know whether that paragraph should be ignored or not? Is it based somehow on the content of the paragraph? Or are you alternating - e.g. ignoring every even-numbered paragraph or something similar?
Probably the simplest way to detect the \n boundary between paragraphs is to use a BufferedReader and call the readLine() method. This will read everything from one \n to the next, and return it as a single String. What you do with it after that is your choice (or, it depends on your answers to the previous questions).
[ June 24, 2002: Message edited by: Jim Yingst ]
 
Chandhrasekar Saravanan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Jim,
I think i am not making to the point. i am trying to build up an general application where we are able to ignore few paragraphs as we wish. you set the criteria by reading the first line and if that doesnt matches with your spec. that paragraph could be ignored.
your suggestion in the last paragraph of previous reply do try to solve the problem , but i still have doubt. the bufferedreader reads ,\n, but every line at the end of the paragraph will have a \n . so how could we make out a difference between an empty line used to separate paragraphs and \n charecter at the end of each line.
are there any easy solutions
Thanks
Regards
Chandhrasekar Saravanan
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmmm why not look at the length of the line. If it is only the length of your "\n" then you can assume it is a blank line and start looking at the next line as the beginning of your next paragraph.
Or just look for 2 "\n" back to back. If you get a hit on that one, then you have an empty line.
Just some thoughts.. I haven't done a lot of text parsing, so I could be totally off. Hope this helps.
reply
    Bookmark Topic Watch Topic
  • New Topic