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
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.
"I'm not back." - Bill Harding, Twister
Joined: Jun 16, 2002
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
Joined: Jan 30, 2000
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 ]
Joined: Jun 16, 2002
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
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.
subject: Ignoring alternate Paragraph from an Input Stream