Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package com.javarush.task.task19.task1912;
  2.  
  3. /*
  4. Ридер обертка 2
  5. */
  6.  
  7. import java.io.ByteArrayOutputStream;
  8. import java.io.PrintStream;
  9.  
  10. public class Solution {
  11. public static TestString testString = new TestString();
  12.  
  13. public static void main(String[] args) {
  14. //запоминаем настоящий PrintStream в специальную переменную
  15. PrintStream consoleStream = System.out;
  16. //Создаем динамический массив
  17. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  18. //создаем адаптер к классу PrintStream
  19. PrintStream stream = new PrintStream(outputStream);
  20. //Устанавливаем его как текущий System.out
  21. System.setOut(stream);
  22. testString.printSomething ();
  23.  
  24. String result = outputStream.toString().replaceAll ("te","??");
  25.  
  26. //Возвращаем все как было
  27. System.setOut(consoleStream);
  28. System.out.println (result);
  29. }
  30.  
  31. public static class TestString {
  32. public void printSomething() {
  33. System.out.println("it's a text for testing");
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement