You cannot modify the supplied code, but you can modify the way you launch it.
What do I offer is a hack that assumes change in System.in. What did I do:
1) I made a test program with single main
method with code you post. I launched it:
$ java -cp dist/Test.jar test.Test <input
Enter the value: You entered: 3
2) I wrote a java programm that does
- redirect input stream (System.in)
- launch test.Test.main
code:
package redirecter;
import java.io.IOException;
import java.io.InputStream;
public class Redirecter {
public static void main(String[] args) {
final InputStream oldIn = System.in;
InputStream hackedIn = new InputStream() {
@Override
public int read() throws IOException {
int b = oldIn.read();
System.out.write(b);
return b;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int res = oldIn.read(b, off, len);
System.out.write(b, off, res);
return res;
}
};
System.setIn(hackedIn);
test.Test.main(args);
}
}
3) I launched old code with a new way:
$ java -cp dist/Test.jar:../Redirecter/dist/Redirecter.jar redirecter.Redirecter <input
Enter the value: 3
You entered: 3
Supplied code wasn't edited; it was just launched by tricky way. All the parameters and jvm options were saved. If you have several entry points, you may use reflection instead of simple call to test.Test.main(args);
Bad point: if someone will edit System.in
in supplied code, the hack will be broken. But it seems to be safe until you work with standard input.