title: Java constant string too long Exception - Runtime
body: <p>I am having a List of DTO which is mapped from a HTTP response(using RestTemplate call) having two value <em>id</em> and <em>content</em>. When I am  iterating over list of DTO's, I am escaping HTML characters in content and replacing some unwated characters using the code below:</p>
  
  <pre><code>    String content = null;
      for(TestDto testDto: testDtoList) {
          try {
              content = StringEscapeUtils.unescapeHtml4(testDto.getContent()).
                                         replaceAll("&lt;style(.+?)&lt;/style&gt;", "").
                                         replaceAll("&lt;script(.+?)&lt;/script&gt;", "").
                                         replaceAll("(?s)&lt;[^&gt;]*&gt;(\\s*&lt;[^&gt;]*&gt;)*", " ").
                                         replaceAll("[^a-zA-Z0-9\\\\.]+", " ").
                                         replace("\\n", " ").
                                         replaceAll("\\\\r","").trim();
              processContent(content);
          } catch (Exception e) {
            System.out.println("Content err: " + e.getMessage());
          }
      }
  </code></pre>
  
  <p>In between the loop, code get halted due to <strong>java constant string too long</strong> exception. Even I am not able to catch this exception.
  How should I handle this problem?</p>
  
  <p>EDIT :</p>
  
  <p>The length of <code>getContent()</code> String can exceeds <code>Integer.MAX_VALUE</code></p>