Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Extending a Reader  RSS feed

 
Meadowlark Bradsher
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write my own FilterReader/ Writer to convert a text file to be XML safe. In other words there are certain characters I will need to convert to entities, "<" type thingies, so that they won't trip the parser.
If I extend a Reader and Writer, perhaps BufferedReader/ Writer, what do I need what do I definitely need to override at minimum?
Or is this called "doing things the hard way"?
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the correct approach. At a minimum, you'll need to override one of the read() method. It depends on how you want to read in the data. One character at a time or in a buffer? To be safe, you should override all the read methods and provide the implementation so one calls the other.
-Peter
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would extend FilterReader and FilterWriter since that is really what they are for.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This discussion has a link to OReilly where they have just such a solution.
------------------
Hope This Helps
Carl Trusiak
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!