"ஹலோ, அமிகோ! இன்று நீங்கள் புதிதாக ஏதாவது செய்வது எப்படி என்று கற்றுக் கொள்ளப் போகிறீர்கள்: System.out ஆப்ஜெக்ட்டை மாற்றவும்."
System.out என்பது கணினி வகுப்பில் அழைக்கப்படும் நிலையான PrintStream மாறியாகும் . இந்த மாறியில் இறுதி மாற்றி உள்ளது, எனவே நீங்கள் அதற்கு ஒரு புதிய மதிப்பை ஒதுக்குங்கள். இருப்பினும், கணினி வகுப்பில் இதைச் செய்ய ஒரு சிறப்பு முறை உள்ளது: setOut(PrintStream stream) . அதைத்தான் நாங்கள் பயன்படுத்துவோம்.

"சுவாரஸ்யமாக இருக்கிறது. அதை நாம் எதை மாற்றுவோம்?"

"வெளியீட்டுத் தரவைச் சேகரிக்கக்கூடிய சில பொருள் எங்களுக்குத் தேவை. இந்த வேலைக்கு ByteArrayOutputStream மிகவும் பொருத்தமானது. இது ஒரு டைனமிக் (மறுஅளவிடக்கூடிய) வரிசை மற்றும் OutputStream இடைமுகத்தைச் செயல்படுத்தும் ஒரு சிறப்பு வகுப்பு."

"வரிசை மற்றும் அவுட்புட்ஸ்ட்ரீம் இடையே ஒரு அடாப்டர்?"

"அப்படி ஏதாவது. இதோ எங்கள் குறியீடு எப்படி இருக்கிறது."

குறியீடு
public static void main(String[] args) throws Exception
{
 //Save the current PrintStream in a special variable
 PrintStream consoleStream = System.out;

 //Create a dynamic array
 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 //Create an adapter for the PrintStream class
 PrintStream stream = new PrintStream(outputStream);
 //Set it as the current System.out
 System.setOut(stream);

 //Call a function that knows nothing about our changes
 printSomething();

 //Convert the data written to our ByteArray into a string
 String result = outputStream.toString();

 //Put everything back to the way it was
 System.setOut(consoleStream);
}

public static void printSomething()
{
 System.out.println("Hi");
 System.out.println("My name is Amigo");
 System.out.println("Bye-bye!");
}

"இந்த வரியை நாங்கள் என்ன செய்வோம்?"

"சரி, நமக்கு என்ன வேண்டும். எடுத்துக்காட்டாக, நாங்கள் அதை மாற்றுவோம். பின்னர் குறியீடு இப்படி இருக்கும்:"

குறியீடு
public static void main(String[] args) throws Exception
{
 //Save the current PrintStream in a special variable
 PrintStream consoleStream = System.out;

 //Create a dynamic array
 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 //Create an adapter for the PrintStream class
 PrintStream stream = new PrintStream(outputStream);
 //Set it as the current System.out
 System.setOut(stream);

 //Call a function that knows nothing about our changes
 printSomething();

 //Convert the data written to our ByteArray into a string
 String result = outputStream.toString();

 //Put everything back to the way it was
 System.setOut(consoleStream);

 //Reverse the string
 StringBuilder stringBuilder = new StringBuilder(result);
 stringBuilder.reverse();
 String reverseString = stringBuilder.toString();

 //Output it to the console
 System.out.println(reverseString);
}

public static void printSomething()
{
 System.out.println("Hi");
 System.out.println("My name is Amigo");
 System.out.println("Bye-bye!");
}

"எவ்வளவு சுவாரஸ்யமானது! இந்த சிறிய வகுப்புகள் வழங்கும் சிறந்த திறன்களைப் பற்றி இப்போது நான் கொஞ்சம் புரிந்து கொள்ளத் தொடங்குகிறேன்."
"சுவாரசியமான பாடத்திற்கு நன்றி, பிலாபோ."