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

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

本文整理了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

private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();

@Before
public void setUpStreams() {
  System.setOut(new PrintStream(outContent));
  System.setErr(new PrintStream(errContent));
}

@After
public void cleanUpStreams() {
  System.setOut(null);
  System.setErr(null);
}

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

@After
public void tearDown() {
  System.setOut(this.out);
}

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

public void stop() {
 if (System.out != originalOutputPrintStream) {
  System.setOut(originalOutputPrintStream);
 }
 if (System.err != originalErrorPrintStream) {
  System.setErr(originalErrorPrintStream);
 }
}

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

@After
public void restoreStreams() {
  if (out != null) {
    System.setOut(out);
  }
  if (err != null) {
    System.setOut(err);
  }
}

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

public void record() {
 os = new PrintStream(output);
 err = new PrintStream(error);
 System.setOut(os);
 System.setErr(err);
}

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

private static void replaceStdOutAndStdErr() {
  stdOut = System.out;
  stdErr = System.err;
  buffer = new ByteArrayOutputStream();
  PrintStream capture = new PrintStream(buffer);
  System.setOut(capture);
  System.setErr(capture);
}

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

@After
public void tearDown() {
 System.setOut(out);
}

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

@Before
public void setUp() {
  System.setOut(new PrintStream(arrayOutputStream));
  System.setErr(new PrintStream(arrayErrorStream));
}

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

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

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

@After
public void tearDown() {
  if (System.out != originalSystemOut) {
    System.out.close();
  }
  if (System.err != originalSystemErr) {
    System.err.close();
  }
  System.setOut(originalSystemOut);
  System.setErr(originalSystemErr);
}

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

@Before
public void setUp() {
  System.setOut(new PrintStream(arrayOutputStream));
  System.setErr(new PrintStream(arrayErrorStream));
}

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

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

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

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

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

@Test
public void testCommandUsageForHello() {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 PrintStream stream = new PrintStream(baos);
 System.setOut(stream);
 itf.execute("hello", "--help");
 assertThat(baos.toString())
   .contains("Usage: ")
   .contains("A command saying hello.") // Summary
   .contains("A simple command to wish you a good day.") // Description
   .contains("-n,--name <name>") // Option
   .contains("your name"); // Option description
}

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

@Test
public void testMissingOption() {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 PrintStream stream = new PrintStream(baos);
 System.setOut(stream);
 itf.execute("hello");
 assertThat(baos.toString())
   .contains("The option", "name", "is required");
}

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

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

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

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

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

@Test
public void testCommandNotFound() {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 PrintStream stream = new PrintStream(baos);
 System.setOut(stream);
 itf.execute("missing");
 assertThat(baos.toString()).contains("The command", "missing", "See", "--help");
 baos.reset();
 itf.execute("missing", "--help");
 assertThat(baos.toString()).contains("The command", "missing", "See", "--help");
}

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

@Test
public void testUsage() {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 PrintStream stream = new PrintStream(baos);
 System.setOut(stream);
 itf.execute("--help");
 assertThat(baos.toString()).contains("hello").contains("bye")
   .doesNotContain("hidden").contains("A command saying hello");
}

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

@Test
public void testHiddenCommandUsage() {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 PrintStream stream = new PrintStream(baos);
 System.setOut(stream);
 itf.execute("hidden", "-h");
 assertThat(baos.toString())
   .contains("-n <value>")
   .doesNotContain("-c ")
   .doesNotContain("count");
}

相关文章