Java escape HTML - string replace slow?

后端 未结 8 593
长情又很酷
长情又很酷 2021-01-22 17:34

I have a Java application that makes heavy use of a large file, to read, process and give through to SolrEmbeddedServer (http://lucene.apache.org/solr/).

One of the func

8条回答
  •  春和景丽
    2021-01-22 18:12

    Apache Commons Lang has a very efficient escapeHtml method in its StringEscapeUtils class.

    It's fairly smart about it, and doesn't use string replacement in the way you describe, but instead iterates through the characters, replacing characters with appropriate entities as it finds them.

    I don't have any benchmarks handy, but if this stuff is on the critical path of your code, you would be wiese to use this off-the-shelf, faster solution.

提交回复
热议问题