Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level19.lesson08.task02;
- /* Ридер обертка 2
- В методе main подмените объект System.out написанной вами ридер-оберткой по аналогии с лекцией
- Ваша ридер-обертка должна заменять все подстроки "te" на "??"
- Вызовите готовый метод printSomething(), воспользуйтесь testString
- Верните переменной System.out первоначальный поток
- Вывести модифицированную строку в консоль.
- */
- import java.io.ByteArrayOutputStream;
- import java.io.PrintStream;
- public class Solution {
- public static TestString testString = new TestString();
- public static void main(String[] args) {
- PrintStream consoleStream = System.out; //save default output to console
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); //new adaptive byte array
- PrintStream stream = new PrintStream(outputStream); //new adapter fot PrintStream class
- System.setOut(stream);//redirect output to array
- testString.printSomething();//output to array
- String result = outputStream.toString().replaceAll("te","??");//adopting output string
- System.setOut(consoleStream); // return out put to console
- System.out.println(result); //output new string
- }
- public static class TestString {
- public void printSomething() {
- System.out.println("it's a text for testing");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement