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