Хэлп
package com.javarush.task.task19.task1912;
/*
Ридер обертка 2
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) throws IOException {
PrintStream out = System.out;
ByteArrayOutputStream tempStorage = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(tempStorage);
System.setOut(printStream);
testString.printSomething(); //now the passed value is stored in array of tempStorage
byte []byteArray = tempStorage.toByteArray();
String result = "";
for(int i = 0; i < byteArray.length - 1; i++){
if(byteArray[i] == 't' && byteArray[i + 1] == 'e'){
result += "??";
i++;
}
else
result += (char)byteArray[i];
}
System.setOut(out);
System.out.println(result);
}
public static class TestString {
public void printSomething() {
System.out.println("it's a text for testing");
}
}
}