src/main/java/com/zandero/utils/StringUtils.java
public static byte[] sanitizeWhitespace(byte[] input) {

		Assert.isFalse(input == null || input.length == 0, "Missing input!");

		try {
			String stringFileData = new String(input, "utf-8");
			return sanitizeWhitespace(stringFileData).getBytes("utf-8");
		}
		catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
public static byte[] sanitizeWhitespace(byte[] input) {

		Assert.isFalse(input == null || input.length == 0, "Missing input!");

		try {
			String stringFileData = new String(input, "utf-8");
			return sanitizeWhitespace(stringFileData).getBytes("utf-8");
		}
		catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
Removes all multiple-consecutive whitespace characters (space, tab, newline) and replaces them with single space.
Also removes leading and trailing spaces.

@param input text to be sanitized as byte array
@return sanitized byte array