本文整理了Java中java.io.PrintStream.flush()
方法的一些代码示例,展示了PrintStream.flush()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintStream.flush()
方法的具体详情如下:
包路径:java.io.PrintStream
类名称:PrintStream
方法名:flush
[英]Ensures that all pending data is sent out to the target stream. It also flushes the target stream. If an I/O error occurs, this stream's error state is set to true.
[中]确保将所有挂起的数据发送到目标流。它还刷新目标流。如果发生I/O错误,则此流的错误状态设置为true。
代码示例来源:origin: apache/flink
@Override
public void printStackTrace(PrintStream s) {
s.print(fullStringifiedStackTrace);
s.flush();
}
代码示例来源:origin: commons-logging/commons-logging
/**
* Write the specified message to the internal logging destination.
*
* @param msg is the diagnostic message to be output.
* @since 1.1
*/
protected static final void logRawDiagnostic(String msg) {
if (diagnosticsStream != null) {
diagnosticsStream.println(msg);
diagnosticsStream.flush();
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public void percentChanged( int percent )
{
for ( int i = lastPercentage + 1; i <= percent; i++ )
{
out.print( '.' );
if ( i % 20 == 0 )
{
out.printf( " %3d%%%n", i );
}
}
lastPercentage = percent;
out.flush();
}
代码示例来源:origin: stackoverflow.com
// Create a stream to hold the output
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
// IMPORTANT: Save the old System.out!
PrintStream old = System.out;
// Tell Java to use your special stream
System.setOut(ps);
// Print some output: goes to your special stream
System.out.println("Foofoofoo!");
// Put things back
System.out.flush();
System.setOut(old);
// Show what happened
System.out.println("Here: " + baos.toString());
代码示例来源:origin: commons-logging/commons-logging
/**
* Write the specified message to the internal logging destination.
* <p>
* Note that this method is private; concrete subclasses of this class
* should not call it because the diagnosticPrefix string this
* method puts in front of all its messages is LogFactory@....,
* while subclasses should put SomeSubClass@...
* <p>
* Subclasses should instead compute their own prefix, then call
* logRawDiagnostic. Note that calling isDiagnosticsEnabled is
* fine for subclasses.
* <p>
* Note that it is safe to call this method before initDiagnostics
* is called; any output will just be ignored (as isDiagnosticsEnabled
* will return false).
*
* @param msg is the diagnostic message to be output.
*/
private static final void logDiagnostic(String msg) {
if (diagnosticsStream != null) {
diagnosticsStream.print(diagnosticPrefix);
diagnosticsStream.println(msg);
diagnosticsStream.flush();
}
}
代码示例来源:origin: apache/geode
public ProcessWrapper sendInput(final String input) {
checkStarting();
final PrintStream ps = new PrintStream(this.process.getOutputStream());
ps.println(input);
ps.flush();
return this;
}
代码示例来源:origin: netty/netty
/**
* Gets the stack trace from a Throwable as a String.
*
* @param cause the {@link Throwable} to be examined
* @return the stack trace as generated by {@link Throwable#printStackTrace(java.io.PrintWriter)} method.
*/
public static String stackTraceToString(Throwable cause) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
cause.printStackTrace(pout);
pout.flush();
try {
return new String(out.toByteArray());
} finally {
try {
out.close();
} catch (IOException ignore) {
// ignore as should never happen
}
}
}
代码示例来源:origin: square/okhttp
private static void sendRequest(OkHttpClient client, String url) {
System.out.printf("%-40s ", url);
System.out.flush();
System.out.println(Platform.get());
Request request = new Request.Builder().url(url).build();
try (Response response = client.newCall(request).execute()) {
Handshake handshake = response.handshake();
System.out.println(handshake.tlsVersion()
+ " "
+ handshake.cipherSuite()
+ " "
+ response.protocol()
+ " "
+ response.code
+ " "
+ response.body.bytes().length
+ "b");
} catch (IOException ioe) {
System.out.println(ioe.toString());
}
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
long currTime = System.currentTimeMillis();
long sentPerSec = linesProcessed / ( (currTime - startTime) / 1000 );
debugStream.println('[' + Redwood.formatTimeDifference(currTime - startTime) + "] Processed " + linesProcessed + " sentences {" + sentPerSec + " sentences / second}... ");
debugStream.println("CAUGHT EXCEPTION ON SENTENCE ID: " + id + " (-1 if not known)");
t.printStackTrace(debugStream);
exceptions += 1;
debugStream.println('[' + Redwood.formatTimeDifference(System.currentTimeMillis() - startTime) + "] DONE");
} catch (Throwable t) {
debugStream.println("FATAL EXCEPTION!");
exceptions += 1;
} finally {
debugStream.flush();
debugStream.close();
代码示例来源:origin: eclipse-vertx/vert.x
private String record(Runnable runnable) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintStream written = new PrintStream(stream);
setStream(written);
runnable.run();
written.flush();
String result = stream.toString();
quiet(() -> {
written.close();
return null;
});
return result;
}
代码示例来源:origin: org.apache.ant/ant
/**
* Encode a string to the output.
*/
private void encodeString(String n) {
PrintStream writer = new PrintStream(out);
writer.print(n);
writer.flush();
}
代码示例来源:origin: drewnoakes/metadata-extractor
@Override
public void onScanCompleted(@NotNull PrintStream log)
{
super.onScanCompleted(log);
OutputStream outputStream = null;
PrintStream stream = null;
try {
outputStream = new FileOutputStream("../wiki/ImageDatabaseSummary.md", false);
stream = new PrintStream(outputStream, false);
writeOutput(stream);
stream.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null)
stream.close();
if (outputStream != null)
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public void close()
{
logger.shutdown();
try
{
logger.awaitTermination();
eventProcessor.join();
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt();
}
finally
{
out.flush();
out.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Renders the AST into 'ASCII art' form and returns that string representation.
*
* @param ast The AST to display.
* @param header The header for the display.
*
* @return The AST in 'ASCII art' form, as a string.
*/
public String showAsString(AST ast, String header) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream( baos );
ps.println( header );
showAst( ast, ps );
ps.flush();
return new String( baos.toByteArray() );
}
代码示例来源:origin: robovm/robovm
/**
* Write the specified message to the internal logging destination.
* <p>
* Note that this method is private; concrete subclasses of this class
* should not call it because the diagnosticPrefix string this
* method puts in front of all its messages is LogFactory@....,
* while subclasses should put SomeSubClass@...
* <p>
* Subclasses should instead compute their own prefix, then call
* logRawDiagnostic. Note that calling isDiagnosticsEnabled is
* fine for subclasses.
* <p>
* Note that it is safe to call this method before initDiagnostics
* is called; any output will just be ignored (as isDiagnosticsEnabled
* will return false).
*
* @param msg is the diagnostic message to be output.
*/
private static final void logDiagnostic(String msg) {
if (diagnosticsStream != null) {
diagnosticsStream.print(diagnosticPrefix);
diagnosticsStream.println(msg);
diagnosticsStream.flush();
}
}
代码示例来源:origin: com.h2database/h2
private void println(String s) {
out.println(s);
out.flush();
}
代码示例来源:origin: vipshop/vjtools
private void run(VMDetailView view) throws Exception {
try {
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), false));
System.out.flush();
Utils.sleep(sleepSeconds * 1000L);
System.out.println("");
System.out.flush();
} catch (NoClassDefFoundError e) {
e.printStackTrace(System.out);
System.out.println(Formats.red("ERROR: Some JDK classes cannot be found."));
System.out.println(" Please check if the JAVA_HOME environment variable has been set to a JDK path.");
System.out.println("");
System.out.flush();
代码示例来源:origin: redisson/redisson
/**
* Gets the stack trace from a Throwable as a String.
*
* @param cause the {@link Throwable} to be examined
* @return the stack trace as generated by {@link Throwable#printStackTrace(java.io.PrintWriter)} method.
*/
public static String stackTraceToString(Throwable cause) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
cause.printStackTrace(pout);
pout.flush();
try {
return new String(out.toByteArray());
} finally {
try {
out.close();
} catch (IOException ignore) {
// ignore as should never happen
}
}
}
代码示例来源:origin: vipshop/vjtools
/**
* 打印单条线程的stack strace,会造成停顿,但比获取全部线程的stack trace停顿少
*/
public void printStack(long tid) throws IOException {
System.out.printf("%n Stack trace of thread %d:%n", tid);
ThreadInfo info = view.vmInfo.getThreadInfo(tid, 20);
if (info == null) {
System.err.println(" TID not exist:" + tid);
return;
}
printSingleThread(info);
System.out.flush();
}
代码示例来源:origin: apache/nifi
public static void main(String[] args) throws IOException {
byte[] bytes = new byte[1024];
System.out.write(System.getProperty("user.dir").getBytes());
System.out.println(":ModifiedResult");
int numRead = 0;
while ((numRead = System.in.read(bytes)) != -1) {
System.out.write(bytes, 0, numRead);
}
System.out.flush();
System.out.close();
}
内容来源于网络,如有侵权,请联系作者删除!