I am having a List of DTO which is mapped from a HTTP response(using RestTemplate call) having two value id and content. 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:
    String content = null;
    for(TestDto testDto: testDtoList) {
        try {
            content = StringEscapeUtils.unescapeHtml4(testDto.getContent()).
                                       replaceAll("<style(.+?)</style>", "").
                                       replaceAll("<script(.+?)</script>", "").
                                       replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", " ").
                                       replaceAll("[^a-zA-Z0-9\\\\.]+", " ").
                                       replace("\\n", " ").
                                       replaceAll("\\\\r","").trim();
            processContent(content);
        } catch (Exception e) {
          System.out.println("Content err: " + e.getMessage());
        }
    }
In between the loop, code get halted due to java constant string too long exception. Even I am not able to catch this exception. How should I handle this problem?
EDIT :
The length of getContent() String can exceeds Integer.MAX_VALUE
 
     
     
     
    