java.lang.System.setOut()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(407)

本文整理了Java中java.lang.System.setOut()方法的一些代码示例,展示了System.setOut()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.setOut()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:setOut

System.setOut介绍

[英]Sets the standard output stream to the given user defined output stream.
[中]将标准输出流设置为给定的用户定义输出流。

代码示例

代码示例来源:origin: stackoverflow.com

  1. private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
  2. private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
  3. @Before
  4. public void setUpStreams() {
  5. System.setOut(new PrintStream(outContent));
  6. System.setErr(new PrintStream(errContent));
  7. }
  8. @After
  9. public void cleanUpStreams() {
  10. System.setOut(null);
  11. System.setErr(null);
  12. }

代码示例来源:origin: EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

  1. @After
  2. public void tearDown() {
  3. System.setOut(this.out);
  4. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. public void stop() {
  2. if (System.out != originalOutputPrintStream) {
  3. System.setOut(originalOutputPrintStream);
  4. }
  5. if (System.err != originalErrorPrintStream) {
  6. System.setErr(originalErrorPrintStream);
  7. }
  8. }

代码示例来源:origin: apache/flink

  1. @After
  2. public void restoreStreams() {
  3. if (out != null) {
  4. System.setOut(out);
  5. }
  6. if (err != null) {
  7. System.setOut(err);
  8. }
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. public void record() {
  2. os = new PrintStream(output);
  3. err = new PrintStream(error);
  4. System.setOut(os);
  5. System.setErr(err);
  6. }

代码示例来源:origin: apache/flink

  1. private static void replaceStdOutAndStdErr() {
  2. stdOut = System.out;
  3. stdErr = System.err;
  4. buffer = new ByteArrayOutputStream();
  5. PrintStream capture = new PrintStream(buffer);
  6. System.setOut(capture);
  7. System.setErr(capture);
  8. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @After
  2. public void tearDown() {
  3. System.setOut(out);
  4. }

代码示例来源:origin: apache/flink

  1. @Before
  2. public void setUp() {
  3. System.setOut(new PrintStream(arrayOutputStream));
  4. System.setErr(new PrintStream(arrayErrorStream));
  5. }

代码示例来源:origin: apache/flink

  1. protected static void resetStreamsAndSendOutput() {
  2. System.setOut(ORIGINAL_STDOUT);
  3. System.setErr(ORIGINAL_STDERR);
  4. System.setIn(ORIGINAL_STDIN);
  5. LOG.info("Sending stdout content through logger: \n\n{}\n\n", outContent.toString());
  6. LOG.info("Sending stderr content through logger: \n\n{}\n\n", errContent.toString());
  7. }

代码示例来源:origin: apache/flink

  1. @After
  2. public void tearDown() {
  3. if (System.out != originalSystemOut) {
  4. System.out.close();
  5. }
  6. if (System.err != originalSystemErr) {
  7. System.err.close();
  8. }
  9. System.setOut(originalSystemOut);
  10. System.setErr(originalSystemErr);
  11. }

代码示例来源:origin: apache/flink

  1. @Before
  2. public void setUp() {
  3. System.setOut(new PrintStream(arrayOutputStream));
  4. System.setErr(new PrintStream(arrayErrorStream));
  5. }

代码示例来源:origin: EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

  1. private void doFizzBuzz(final int n, final String s) throws IOException {
  2. final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  3. final BufferedOutputStream bos = new BufferedOutputStream(baos);
  4. System.setOut(new PrintStream(bos));
  5. this.fb.fizzBuzz(n);
  6. System.out.flush();
  7. String platformDependentExpectedResult = s.replaceAll("\\n", System.getProperty("line.separator"));
  8. assertEquals(platformDependentExpectedResult, baos.toString());
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testCommandUsageForGoodbye() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("bye", "--help");
  7. assertThat(baos.toString())
  8. .contains("A command saying goodbye.") // Summary
  9. .contains("-n <value>"); // Option
  10. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testCommandUsageForHello() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("hello", "--help");
  7. assertThat(baos.toString())
  8. .contains("Usage: ")
  9. .contains("A command saying hello.") // Summary
  10. .contains("A simple command to wish you a good day.") // Description
  11. .contains("-n,--name <name>") // Option
  12. .contains("your name"); // Option description
  13. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testMissingOption() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("hello");
  7. assertThat(baos.toString())
  8. .contains("The option", "name", "is required");
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testInvalidValue() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("hidden", "-n", "vert.x", "-c", "hello");
  7. assertThat(baos.toString())
  8. .contains("The value 'hello' is not accepted by 'count'");
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testMissingValue() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("hello", "-n");
  7. assertThat(baos.toString())
  8. .contains("The option 'name' requires a value");
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testCommandNotFound() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("missing");
  7. assertThat(baos.toString()).contains("The command", "missing", "See", "--help");
  8. baos.reset();
  9. itf.execute("missing", "--help");
  10. assertThat(baos.toString()).contains("The command", "missing", "See", "--help");
  11. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testUsage() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("--help");
  7. assertThat(baos.toString()).contains("hello").contains("bye")
  8. .doesNotContain("hidden").contains("A command saying hello");
  9. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Test
  2. public void testHiddenCommandUsage() {
  3. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  4. PrintStream stream = new PrintStream(baos);
  5. System.setOut(stream);
  6. itf.execute("hidden", "-h");
  7. assertThat(baos.toString())
  8. .contains("-n <value>")
  9. .doesNotContain("-c ")
  10. .doesNotContain("count");
  11. }

相关文章