public static void main(String[] args) {
PrintStream console = new PrintStream(System.out);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(bo);
System.setOut(stream);
testString.printSomething();
System.setOut(console);
String[] list = bo.toString().trim().split("\r");
StringBuilder sb = new StringBuilder();
int count = 0;
for (int i = 0; i < list.length; i++) {
sb.append(list[i]);
count++;
if (count==2) {
sb.append("\n"+"JavaRush - курсы Java онлайн");
count=0;
}
}
System.out.println(sb.toString());
}
После колдунства, всё заработало, но я так и не понял, что нужно было валидатору, учитывая, что результат в ИнтелИдеа, был одинаковый.
public static void main(String[] args) {
PrintStream console = new PrintStream(System.out);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(bo);
System.setOut(stream);
testString.printSomething();
System.setOut(console);
char[] ch = bo.toString().toCharArray();
for (int i = 0; i < ch.length; i++) {
if (ch[i]==13) ch[i]=10;
}
String str = new String(ch);
String[] list = str .replace("\n\n", "\n") .split("\n");
StringBuilder sb = new StringBuilder();
int count = 0;
for (int i = 0; i < list.length; i++) {
sb.append(list[i] + "\n");
count++;
if (count==2) {
sb.append("JavaRush - курсы Java онлайн" + "\n");
count=0;
}
}
System.out.println(sb.toString());
}
Не спрашивайте, почему я городил такие штуки, внятного ответа нет, но это сработало. За красотой и лаконичностью не гнался, так что извиняюсь.