Skip to content

Instantly share code, notes, and snippets.

@argan
Last active December 13, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save argan/4986058 to your computer and use it in GitHub Desktop.
Save argan/4986058 to your computer and use it in GitHub Desktop.
import java.io.OutputStream;
import java.io.PrintStream;
public class Unicorn {
private static String str1 = "UNICORN #1: PAT THIS UNICORN ONCE";
private static String str2 = "UNICORN #2: PAT THIS UNICORN ONCE";
static class Printer extends PrintStream {
private PrintStream origin;
private boolean first = false;
private boolean second = false;
public Printer(OutputStream out) {
super(out);
this.origin = new PrintStream(out);
}
@Override
public void println(String x) {
if (x.equals(str1)) {
if (!first) {
origin.println(x);
first = true;
}
} else if (x.equals(str2)) {
if (!second) {
origin.println(x);
second = true;
}
} else {
origin.println(x);
}
}
}
static {
PrintStream origin = System.out;
System.setOut(new Printer(origin));
}
public static boolean pat() {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment