public String compress(final String data) throws IOException { final ReadLine r = new UncommentReadLine(new ReadLineReader(new StringReader(data))); final StringBuilder sb = new StringBuilder(); final StringBuilder full = new StringBuilder(); String s = null; boolean startDone = false; while ((s = r.readLine()) != null) { append(full, s); if (s.startsWith("@startuml")) { startDone = true; } else if (s.startsWith("@enduml")) { return sb.toString(); } else if (startDone) { append(sb, s); } } if (startDone == false) { return compressOld(full.toString()); } return sb.toString(); }