public static String replace(final String inputText, final String begin, final String newBegin, final String end, final String newEnd) throws IOException {
final BeginEndTokenHandler tokenHandler = new BeginEndTokenHandler(newBegin, newEnd);
final ByteArrayInputStream in = new ByteArrayInputStream(inputText.getBytes());
final InputStream replacementStream = new DelimitedTokenReplacementInputStream(in, begin, end, tokenHandler, true);
// SwizzleStream block read methods are broken so read byte at a time
final StringBuilder sb = new StringBuilder();
int i = replacementStream.read();
while (i != -1) {
sb.append((char) i);
i = replacementStream.read();
}
final String newServerXml = sb.toString();
IO.close(replacementStream);
return newServerXml;
}