package cn.com.qmth.examcloud.commons.helpers; import java.io.ByteArrayOutputStream; import java.io.PrintStream; /** * 黑洞(PrintStream)构建器 * * @author WANGWEI * @date 2019年3月28日 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved. */ public class BlackHolePrintStreamBuilder { /** * 创建BlackHolePrintStream * * @author WANGWEI * @return */ public static PrintStream build() { return new BlackHolePrintStream(new ByteArrayOutputStream()); } /** * 黑洞(PrintStream) * * @author WANGWEI * @date 2019年3月28日 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved. */ private static class BlackHolePrintStream extends PrintStream { @Override public void close() { super.close(); } ByteArrayOutputStream outputStream; /** * 私有构造函数 * * @param out */ private BlackHolePrintStream(ByteArrayOutputStream outputStream) { super(outputStream); this.outputStream = outputStream; } @Override public void println(String x) { outputStream.reset(); } @Override public void print(String x) { outputStream.reset(); } } }