• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read Data from one buffer to another.

 
Shanu Khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m reading Data from a html file Via BufferedReader line by line and replcaing some data successfully.when i m printing it on console its prints a fresh n fine data.
now i have a problem that how can i Parse that fresh html data without writing it to another file.


 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I'm not really sure what your problem is. Please can you give more details on what you want the code to do and what it is actually doing.
 
Shanu Khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:Welcome to the Ranch.

I'm not really sure what your problem is. Please can you give more details on what you want the code to do and what it is actually doing.


Shanu wrote:
yes i m trying to Parse a html file but it contains some entity which is creating problem with Parser so i have replaced it with blank string in buffer
now i have fresh data in String buffer which i need to parse but when i m passing String buffer reference to parser it shows me a error @ line 29,30.


 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried printing the contents to the screen before and after you have changed the problem part to make sure you are changing it correctly.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why after each line of data from the file is added to the StringBuffer you treat the content of the StringBuffer as a file name and try to parse the content of the file it represents! Am I missing something? Are you actually trying to parse the content of the StringBuffer? If so then surely the parsing should be done outside of the loop reading the file and the content of the StringBuffer should not be treated as a file name but as XML to be parsed!
 
Shanu Khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanu Khan wrote:
@Richard==Actually i m checking each line if it contains unacceptable entity in html then replace it with space and then put the fresh file line into buffer(StringBuffer).
and so on i have checked all lines and fresh data are now in string buffer. which i need to parse without write it to a new file.

@Tony ==As per your question i have tried to print the fresh data which i assume..is correct.
now the problem is how to parse it from string buffer...i m stuck over here...

 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shanu Khan wrote:
Shanu Khan wrote:
@Richard==Actually i m checking each line if it contains unacceptable entity in html then replace it with space and then put the fresh file line into buffer(StringBuffer).
and so on i have checked all lines and fresh data are now in string buffer.

That I understood.
which i need to parse without write it to a new file.

But you have placed the code to parse the content of the StringBuffer inside the loop in which is reading the data into the buffer; it should be outside the loop! The code to parse the XML is most definitely faulty and should turn the content of the StringBuilder into an InputSource or InputStream and then used in the parse() method of the DocumentBuilder. It most definitely should not be used as the argument to a File! A File object represents a file name and not not not the content of the file.

 
Shanu Khan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The code to parse the XML is most definitely faulty and should turn the content of the StringBuilder into an InputSource or InputStream and then used in the parse() method of the DocumentBuilder. It most definitely should not be used as the argument to a File! A File object represents a file name and not not not the content of the file.


can you elaborate more on this that how to we can StringBuilder into InputSource.
Might be i m wrong..i think i have to to write this data in any file first then have to read it again.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to skin this cat. A simple naive example -

StringBuffer -> String -> StringReader -> InputSource .

I suspect your whole approach is flawed since you are also discarding the EOL characters (they may or may not be important depending on your use of the data) and the approach does not scale well. Any time you have to read the whole of a file into memory, as one does when using DOM, you have a potential for 'out of memory' and in your case you compound the possible DOM memory problem by also holding the file content in a StringBuffer. Since I don't know how big the file is or how you are using the DOM content I can't really suggest a better solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic