Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringReader instead of StringBufferInputStream 1

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
Ok so StringBufferInputStream has been deprecated and according to the following url you should use StringReader.


My problem is that I need to convert a string into an InputStream not a Reader, I can parse the InputStream to (for example) SAXParser.parse.
This method does not take a Reader as a parameter.
Reader and InputStream are inconvertible types.

So how do I use StringReader to create an InputStream from a String?

At the moment I use new ByteArrayInputStream to create an InputStream from a String:

new ByteArrayInputStream(myString.getBytes())



Greetings, Harm Meijer
 
You can use an InputSource since it can be constructed from a Reader or an InputStream. There is a method:

SAXParser.parse(InputSource, HandlerXXX);

Hope this helps.
 
Yes thanks, I have changed my class that handles the processing of incomming xml:

Thread tt = new Thread(new processIncommingXMLMessage(new InputSource(new StringReader(sbIn.toString())),this));

constructor for processIncommingXMLMessage:
public processIncommingXMLMessage(InputSource is,burrowing.SimpleChatServer caller){
this.inpSrc = is;
this.caller = caller;
}

and the run method:
public void run(){
try{
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(inpSrc,this);



I had to change all the code where I created a new instance of processIncommingXMLMessage though.



Greetings, Harm Meijer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top