public static String wordWrap(String message, int lineWidth) {
		if (message.length() < lineWidth) {
			return message;
		}
		
		//Iterate through message, replacing spaces with newlines if it's been more than lineWidth
		//characters since our last newline
		int lastSpace = 0;
		int lastNewline = 0;
		
		StringBuilder out = new StringBuilder(message);
		
		if (out.indexOf("\n", lastNewline + 1) > 0 && out.indexOf("\n", lastNewline + 1) < lineWidth) {
			lastNewline = out.indexOf("\n", lastNewline + 1);
		}
		
		while (true) {
			int idx = out.indexOf(" ", lastSpace + 1);
			
			if (idx < 0) {
				break;
			}
			
			if ((idx - lastNewline) > lineWidth) {
				//Been too long, replace lastSpace with a newline character
				out.replace(lastSpace, lastSpace + 1, "\r\n");
				lastNewline = lastSpace;
				
				if (out.indexOf("\n", lastNewline + 1) > 0 && out.indexOf("\n", lastNewline + 1) < lineWidth) {
					lastNewline = out.indexOf("\n", lastNewline + 1);
				}
			}
			
			lastSpace = idx;
		}
		
		return out.toString();
	}