0

i know you can convert InputStream to string using something like :

 public static String convertStreamToString(ServletInputStream is) {
    java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
    return s.hasNext() ? s.next() : "";
}

Which is fine, however my input stream is an xml I parse using SAX Parser, and I was wondering if there is an faster way to get the XML as string, since the parser already loops through the stream.

I can get it to work by concating the string in all the events,but I was wondering if there's a faster/built in way to do so, since this code is really performance-sensitive

4

1 回答 1

0

如果您必须使用 SAX,似乎没有内置方法,请参阅Echoing an XML File with the SAX Parser。或者,如果可以,请考虑使用StAX 。

于 2013-05-06T07:07:11.800 回答