@@ -0,0 +1,1112 @@
+package com.github.jrialland.javaformatter;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.StringReader;%0Aimport java.io.StringWriter;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic final class StringUtil %7B%0A%0A%09public static String toJavaComment(String txt) %7B%0A%09%09try %7B%0A%09%09%09BufferedReader br = new BufferedReader(new StringReader(txt));%0A%09%09%09StringWriter sw = new StringWriter();%0A%09%09%09String line = null;%0A%09%09%09boolean first = true;%0A%09%09%09while ((line = br.readLine()) != null) %7B%0A%09%09%09%09if (first) %7B%0A%09%09%09%09%09sw.append(%22/* %22);%0A%09%09%09%09%09first = false;%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09sw.append(%22 * %22);%0A%09%09%09%09%7D%0A%09%09%09%09sw.append(line.replaceAll(%22%5Cr%7C%5Cn%22, %22%22));%0A%09%09%09%09sw.append(%22%5Cn%22);%0A%09%09%09%7D%0A%09%09%09sw.append(%22 */%5Cn%22);%0A%09%09%09return sw.toString();%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static String insertHeader(String header, String javaSource) %7B%0A%09%09Matcher m = Pattern.compile(%22package%7Cimport%7Cpublic%7Cprotected%7Cprivate%7Cclass%7Cinterface%7C@enum%7Cenum%22).matcher(javaSource);%0A%09%09if(m.find()) %7B%0A%09%09%09return header + javaSource.substring(m.start());%0A%09%09%7D else %7B%0A%09%09%09return javaSource;%0A%09%09%7D%0A%09%7D%0A%7D%0A

support for changing header text in source files