Esempio n. 1
0
 @Test
 public void testEscapeXml() {
   assertEquals("abcd", StringUtils.escapeXml("abcd"));
   assertEquals(
       "a<table border="0" color='red'>b<c</table>d",
       StringUtils.escapeXml("a<table border=\"0\" color=\'red\'>b&lt;c</table>d"));
 }
Esempio n. 2
0
  @Test
  public void testEscapeXmlPerformance() {
    String html = "a<table border=\"0\" color=\'red\'>b&lt;c</table>d";
    // char[] html = "a<table border=\"0\" color=\'red\'>b&lt;c</table>d".toCharArray();

    int count = profile ? 10 * 1000 * 1000 : 1000;
    long start = System.nanoTime();
    for (int i = 0; i < count; i++) {
      StringUtils.escapeXml(html);
    }
    long elapsed = System.nanoTime() - start;
    DecimalFormat format = new DecimalFormat("###,##0.###");
    System.out.println(
        "elapsed: "
            + format.format(elapsed)
            + "ns, tps: "
            + format.format(1000L * 1000L * 1000L * (long) count / elapsed));
  }
Esempio n. 3
0
 public byte[] filter(String key, byte[] value) {
   return StringUtils.escapeXml(value);
 }
Esempio n. 4
0
 public char[] filter(String key, char[] value) {
   return StringUtils.escapeXml(value);
 }
Esempio n. 5
0
 public String filter(String key, String value) {
   return StringUtils.escapeXml(value);
 }
Esempio n. 6
0
 @Test
 public void escapeXmlBytes() {
   assertEquals("中&lt;文&gt;字&quot;符", new String(StringUtils.escapeXml("中<文>字\"符".getBytes())));
 }