java.io.PrintWriter.flush()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(242)

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

PrintWriter.flush介绍

[英]Ensures that all pending data is sent out to the target. It also flushes the target. If an I/O error occurs, this writer's error state is set to true.
[中]确保将所有挂起的数据发送到目标。它还刷新目标。如果发生I/O错误,则此写入程序的错误状态设置为true。

代码示例

代码示例来源:origin: apache/incubator-dubbo

void println() {
  if (!_isNewline) {
    _dbg.println();
    _dbg.flush();
  }
  _isNewline = true;
  _column = 0;
}

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

@Override
public void printStackTrace(PrintWriter s) {
  s.print(fullStringifiedStackTrace);
  s.flush();
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * write lines.
 *
 * @param os    output stream.
 * @param lines lines.
 * @throws IOException
 */
public static void writeLines(OutputStream os, String[] lines) throws IOException {
  PrintWriter writer = new PrintWriter(new OutputStreamWriter(os));
  try {
    for (String line : lines) {
      writer.println(line);
    }
    writer.flush();
  } finally {
    writer.close();
  }
}

代码示例来源:origin: facebook/stetho

private static String formatThrowable(Throwable t) {
 StringWriter buf = new StringWriter();
 PrintWriter writer = new PrintWriter(buf);
 t.printStackTrace();
 writer.flush();
 return buf.toString();
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Writes out data from this Object.
 * @param w Data is written to this Writer
 */
public void writeData(Writer w) {
 PrintWriter out = new PrintWriter(w);
 // all lines have one rule per line
 for (UnaryRule ur : this) {
  out.println(ur.toString(index));
 }
 out.flush();
}

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

PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true);
) {
  writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
  writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
  writer.append(CRLF).append(param).append(CRLF).flush();
  writer.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + textFile.getName() + "\"").append(CRLF);
  writer.append("Content-Type: text/plain; charset=" + charset).append(CRLF); // Text file itself must be saved in this charset!
  writer.append(CRLF).flush();
  Files.copy(textFile.toPath(), output);
  writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
  writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())).append(CRLF);
  writer.append("Content-Transfer-Encoding: binary").append(CRLF);
  writer.append(CRLF).flush();
  Files.copy(binaryFile.toPath(), output);
  writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary.
  writer.append("--" + boundary + "--").append(CRLF).flush();

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

public void write(String txt, OutputStream out) {
  PrintWriter printer = new PrintWriter(out);
  printer.print(txt);
  printer.flush();
  //it is very unpolite to close someone else's streams!
  //printer.close();
}

代码示例来源:origin: line/armeria

@Override
  public void dump(OutputStream output) {
    // Do not close this writer in order to keep output stream open.
    final PrintWriter p = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
    p.printf("Dump of %s:%n", this);
    for (int i = 0; i < values.size(); i++) {
      p.printf("<%d> %s%n", i, values.get(i));
    }
    p.flush();
  }
}

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

public void dumpOptimizerPlanAsJSON(OptimizedPlan plan, File toFile) throws IOException {
  PrintWriter pw = null;
  try {
    pw = new PrintWriter(new FileOutputStream(toFile), false);
    dumpOptimizerPlanAsJSON(plan, pw);
    pw.flush();
  } finally {
    if (pw != null) {
      pw.close();
    }
  }
}

代码示例来源:origin: org.testng/testng

private static String buildStackTrace(Throwable t, boolean toHtml, StackTraceType type) {
 StringWriter sw = new StringWriter();
 PrintWriter pw = new PrintWriter(sw);
 t.printStackTrace(pw);
 pw.flush();
 String stackTrace = sw.getBuffer().toString();
 if (type == StackTraceType.SHORT && !isTooVerbose()) {
  stackTrace = filterTrace(sw.getBuffer().toString());
 }
 if (toHtml) {
  stackTrace = escapeHtml(stackTrace);
 }
 return stackTrace;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void nestedRuntimeExceptionWithNoRootCause() {
  String mesg = "mesg of mine";
  // Making a class abstract doesn't _really_ prevent instantiation :-)
  NestedRuntimeException nex = new NestedRuntimeException(mesg) {};
  assertNull(nex.getCause());
  assertEquals(nex.getMessage(), mesg);
  // Check printStackTrace
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  nex.printStackTrace(pw);
  pw.flush();
  String stackTrace = new String(baos.toByteArray());
  assertTrue(stackTrace.contains(mesg));
}

代码示例来源:origin: gocd/gocd

public void typeInputToConsole(List<String> inputs) {
  for (String input : inputs) {
    processInputStream.println(input);
    processInputStream.flush();
  }
  processInputStream.close();
}

代码示例来源:origin: alibaba/Sentinel

private static void writeDefaultBlockedPage(HttpServletResponse response) throws IOException {
  PrintWriter out = response.getWriter();
  out.print(DEFAULT_BLOCK_MSG);
  out.flush();
  out.close();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public void close() {
    super.flush();
    super.close();
    setCommitted(true);
  }
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * write lines.
 *
 * @param os    output stream.
 * @param lines lines.
 * @throws IOException
 */
public static void writeLines(OutputStream os, String[] lines) throws IOException {
  PrintWriter writer = new PrintWriter(new OutputStreamWriter(os));
  try {
    for (String line : lines) {
      writer.println(line);
    }
    writer.flush();
  } finally {
    writer.close();
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Prints full exception stack trace, from top to root cause, into a String.
 */
public static String exceptionChainToString(Throwable t) {
  StringWriter sw = new StringWriter();
  PrintWriter pw = new PrintWriter(sw, true);
  while (t != null) {
    t.printStackTrace(pw);
    t = t.getCause();
  }
  pw.flush();
  sw.flush();
  return sw.toString();
}

代码示例来源:origin: apache/incubator-gobblin

public void saveToFile(final String text, final Path destPath)
  throws IOException {
 try (PrintWriter out = new PrintWriter(
   Files.newBufferedWriter(destPath, StandardCharsets.UTF_8))) {
  out.println(text);
  out.flush();
 }
}

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

@Test
public void testSpanningChild() {
  long basicCuboid = getBaseCuboid(10);
  List<Long> cuboids = genRandomCuboids(basicCuboid, 50);
  long testCuboid = cuboids.get(10);
  System.out.println(cuboids);
  CuboidTree cuboidTree = CuboidTree.createFromCuboids(cuboids);
  PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));
  cuboidTree.print(out);
  out.flush();
  List<Long> spanningChildren = cuboidTree.getSpanningCuboid(testCuboid);
  System.out.println(testCuboid + ":" + spanningChildren);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void writeData(Writer w) {//throws IOException {
 PrintWriter out = new PrintWriter(w);
 StringBuilder sb = new StringBuilder();
 sb.append(lexOptions.toString());
 sb.append("parserParams ").append(tlpParams.getClass().getName()).append("\n");
 sb.append("forceCNF ").append(forceCNF).append("\n");
 sb.append("doPCFG ").append(doPCFG).append("\n");
 sb.append("doDep ").append(doDep).append("\n");
 sb.append("freeDependencies ").append(freeDependencies).append("\n");
 sb.append("directional ").append(directional).append("\n");
 sb.append("genStop ").append(genStop).append("\n");
 sb.append("distance ").append(distance).append("\n");
 sb.append("coarseDistance ").append(coarseDistance).append("\n");
 sb.append("dcTags ").append(dcTags).append("\n");
 sb.append("nPrune ").append(nodePrune).append("\n");
 out.print(sb.toString());
 out.flush();
}

代码示例来源:origin: line/armeria

public void dump(OutputStream output) {
  // Do not close this writer in order to keep output stream open.
  final PrintWriter p = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
  p.printf("Dump of %s:%n", this);
  dump(p, root, 0);
  p.flush();
}

相关文章