code: String cleanOutputWhitespace(String str) {
  		StringBuilder sb = new StringBuilder(str.length());
  
  		int currentWhitespaceStart = -1;
  		int startOfLine = 0;
  
  		for (int i = 0; i < str.length(); i++) {
  			char c = str.charAt(i);
  
  			boolean isInlineWhitespace = c == ' ' || c == '\t';
  
  			if (isInlineWhitespace && currentWhitespaceStart == -1)
  				currentWhitespaceStart = i;
  
  			if (!isInlineWhitespace) {
  				if (c != '\n' && currentWhitespaceStart > 0 && currentWhitespaceStart != startOfLine) {
  					sb.append(' ');
  				}
  				currentWhitespaceStart = -1;
  			}
  
  			if (c == '\n')
  				startOfLine = i + 1;
  
  			if (!isInlineWhitespace)
  				sb.append(c);
  		}
  
  		return sb.toString();
  	}
docs: Cleans inline whitespace in the following way:
  - Removes all whitespace from the start and end of line (including just before a \n)
  - Turns all consecutive space and tab runs into single spaces (HTML style)