StringBufferInputStream has been deprecated; the documentation recommends you use StringReader instead. Yet, many stream-related methods in other classes (often those that predate the deprecation) will only accept an InputStream. How does one send an InputStream that came from an in-memory string?

Joseph Shelby

Nearest I can figure out is you have to convert the String to its byte array, and pass that into a ByteArrayInputStream. I had to do this because I was passing properties data over the 'net, embeded as CDATA in XML, and I couldn't therefore pass the whole network stream over to the Properties loader.

String s = ...;
Properties p = new Properties();
byte[] bArray = s.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bArray);
p.load(bais);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact