core/src/main/java/nl/nn/adapterframework/util/Misc.java
/**
	 * Copies the content of a reader into a string, adds specified string to the end of the line, if specified.
	 * <p>
	 *     Example:
	 *     <pre>
	 *         Reader r = new StringReader("<root> WeAreFrank'</root> \n";
	 *         String s = Misc.readerToString(r, "!!", true);
	 *         System.out.println(s);
	 *         // prints "&lt;root&gt; WeAreFrank!!&lt;/root&gt;"
	 *     </pre>
	 * </p>
	 * @param xmlEncode if set to true, applies XML encodings to the content of the reader
	 */
Copies the content of a reader into a string, adds specified string to the end of the line, if specified.
Copies the content of a reader into a string adds specified string to the end of the line if specified .
public static String readerToString(Reader reader, String endOfLineString, boolean xmlEncode) throws IOException {
		StringBuilder sb = new StringBuilder();
		int curChar = -1;
		int prevChar = -1;
		try {
			while ((curChar = reader.read()) != -1 || prevChar == '\r') {
				if (prevChar == '\r' || curChar == '\n') {
					if (endOfLineString == null) {
						if (prevChar == '\r')
							sb.append((char) prevChar);
						if (curChar == '\n')
							sb.append((char) curChar);
					}
					else {
						sb.append(endOfLineString);
					}
				}
				if (curChar != '\r' && curChar != '\n' && curChar != -1) {
					String appendStr =""+(char) curChar;
					sb.append(xmlEncode ? XmlUtils.encodeChars(appendStr) : appendStr);
				}
				prevChar = curChar;
			}
			return sb.toString();
		} finally {
			reader.close();
		}
	}
public static String readerToString ( Reader reader , String endOfLineString , boolean xmlEncode ) throws IOException { StringBuilder sb = new StringBuilder ( ) ; int curChar = - 1 ; int prevChar = - 1 ; try { while ( ( curChar = reader . read ( ) ) != - 1 || prevChar == '\r' ) { if ( prevChar == '\r' || curChar == '\n' ) { if ( endOfLineString == null ) { if ( prevChar == '\r' ) sb . append ( ( char ) prevChar ) ; if ( curChar == '\n' ) sb . append ( ( char ) curChar ) ; } else { sb . append ( endOfLineString ) ; } } if ( curChar != '\r' && curChar != '\n' && curChar != - 1 ) { String appendStr = "" + ( char ) curChar ; sb . append ( xmlEncode ? XmlUtils . encodeChars ( appendStr ) : appendStr ) ; } prevChar = curChar ; } return sb . toString ( ) ; } finally { reader . close ( ) ; } }
Copies the content of a reader into a string, adds specified string to the end of the line, if specified.
Copies the content of a reader into a string adds specified string to the end of the line if specified .