本文整理了Java中java.io.PrintWriter.checkError()
方法的一些代码示例,展示了PrintWriter.checkError()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PrintWriter.checkError()
方法的具体详情如下:
包路径:java.io.PrintWriter
类名称:PrintWriter
方法名:checkError
[英]Flushes this writer and returns the value of the error flag.
[中]
代码示例来源:origin: groovy/groovy-core
public boolean checkError() {
return getResponseWriter().checkError();
}
public void close() {
代码示例来源:origin: spring-projects/spring-session
@Override
public boolean checkError() {
return this.delegate.checkError();
}
代码示例来源:origin: log4j/log4j
/** sends a message to each of the clients in telnet-friendly output. */
public synchronized void send(final String message) {
Iterator ce = connections.iterator();
for(Iterator e = writers.iterator();e.hasNext();) {
ce.next();
PrintWriter writer = (PrintWriter)e.next();
writer.print(message);
if(writer.checkError()) {
ce.remove();
e.remove();
}
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
public void flush()
{
if ( out != null )
{
out.flush();
if ( out.checkError() && exception == null )
{
try
{
// Thrown to fill in stack trace elements.
throw new IOException( "Failure flushing output." );
}
catch ( final IOException e )
{
exception = e;
}
}
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
public void close()
{
if ( out != null )
{
out.close();
if ( out.checkError() && exception == null )
{
try
{
// Thrown to fill in stack trace elements.
throw new IOException( "Failure closing output." );
}
catch ( final IOException e )
{
exception = e;
}
}
}
}
代码示例来源:origin: stackoverflow.com
ServerSocket serverSocket = new ServerSocket(4444);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
while (true) {
out.println("output");
if (out.checkError()) System.out.println("ERROR writing data to socket !!!");
System.out.println(clientSocket.isConnected());
System.out.println(clientSocket.getInputStream().read());
// thread sleep ...
// break condition , close sockets and the like ...
}
代码示例来源:origin: vavr-io/vavr
/**
* Sends the string representations of this to the {@link PrintWriter}.
* If this value consists of multiple elements, each element is displayed in a new line.
*
* @param writer The PrintWriter to write to
* @throws IllegalStateException if {@code PrintWriter.checkError()} is true after writing to writer.
*/
@GwtIncompatible("java.io.PrintWriter is not implemented")
default void out(PrintWriter writer) {
for (T t : this) {
writer.println(String.valueOf(t));
if (writer.checkError()) {
throw new IllegalStateException("Error writing to PrintWriter");
}
}
}
代码示例来源:origin: Netflix/servo
private void write(Socket socket, Iterable<Metric> metrics) throws IOException {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(),
"UTF-8"));
int count = writeMetrics(metrics, writer);
boolean checkError = writer.checkError();
if (checkError) {
throw new IOException("Writing to socket has failed");
}
checkNoReturnedData(socket);
LOGGER.debug("Wrote {} metrics to graphite", count);
}
代码示例来源:origin: cmusphinx/sphinx4
/**
* sends a command, retries on error which will attempt to repair a dead socket
*
* @param command the command
* @return true if command was sent ok
*/
public synchronized boolean sendCommand(String command) {
final int maxTries = 2;
for (int i = 0; i < maxTries; i++) {
if (!checkOpen()) {
continue;
}
outWriter.println(command);
if (outWriter.checkError()) {
close();
System.err.println("IO error while sending " + command);
} else {
return true;
}
}
return false;
}
代码示例来源:origin: org.apache.ant/ant
/**
* Print changelog to file specified in task.
*
* @param entrySet the entry set to write.
* @throws BuildException if there is an error writing changelog.
*/
private void writeChangeLog(final CVSEntry[] entrySet)
throws BuildException {
try (final PrintWriter writer = new PrintWriter(
new OutputStreamWriter(Files.newOutputStream(destFile.toPath()), "UTF-8"))) {
new ChangeLogWriter().printChangeLog(writer, entrySet);
if (writer.checkError()) {
throw new IOException("Encountered an error writing changelog");
}
} catch (final UnsupportedEncodingException uee) {
getProject().log(uee.toString(), Project.MSG_ERR);
} catch (final IOException ioe) {
throw new BuildException(ioe.toString(), ioe);
}
}
}
代码示例来源:origin: jmxtrans/jmxtrans
@Override
public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
Socket socket = null;
PrintWriter writer = null;
try {
socket = pool.borrowObject(address);
writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8), true);
for (String formattedResult : messageFormatter.formatResults(results, server)) {
log.debug("OpenTSDB Message: {}", formattedResult);
writer.write("put " + formattedResult + "\n");
}
} catch (ConnectException e) {
log.error("Error while connecting to OpenTSDB", e);
} finally {
if (writer != null && writer.checkError()) {
log.error("Error writing to OpenTSDB, clearing OpenTSDB socket pool");
pool.invalidateObject(address, socket);
} else {
pool.returnObject(address, socket);
}
}
}
代码示例来源:origin: org.codehaus.plexus/plexus-utils
@Override
public void run()
boolean outError = out != null ? out.checkError() : false;
if ( out.checkError() )
代码示例来源:origin: alibaba/jvm-sandbox
while (!writer.checkError()
&& !isBrokenRef.get()
&& !Thread.currentThread().isInterrupted()) {
代码示例来源:origin: org.apache.ant/ant
if (writer.checkError()) {
throw new IOException("Encountered an error writing tagdiff");
代码示例来源:origin: org.apache.ant/ant
private void writeManifest(ZipOutputStream zOut, Manifest manifest)
throws IOException {
StreamUtils.enumerationAsStream(manifest.getWarnings())
.forEach(warning -> log("Manifest warning: " + warning, Project.MSG_WARN));
zipDir((Resource) null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE,
JAR_MARKER);
// time to write the manifest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_ENCODING);
PrintWriter writer = new PrintWriter(osw);
manifest.write(writer, flattenClassPaths);
if (writer.checkError()) {
throw new IOException("Encountered an error writing the manifest");
}
writer.close();
ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray());
try {
super.zipFile(bais, zOut, MANIFEST_NAME,
System.currentTimeMillis(), null,
ZipFileSet.DEFAULT_FILE_MODE);
} finally {
// not really required
FileUtils.close(bais);
}
super.initZipOutputStream(zOut);
}
代码示例来源:origin: org.apache.ant/ant
if (writer.checkError()) {
throw new IOException("Encountered an error writing jar index");
代码示例来源:origin: jmxtrans/jmxtrans
@Override
public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
Socket socket = null;
PrintWriter writer = null;
try {
socket = pool.borrowObject(address);
writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8), true);
List<String> typeNames = this.getTypeNames();
for (Result result : results) {
log.debug("Query result: {}", result);
Object value = result.getValue();
if (isValidNumber(value)) {
String line = KeyUtils.getKeyString(server, query, result, typeNames, rootPrefix)
.replaceAll("[()]", "_") + " " + value.toString() + " "
+ result.getEpoch() / 1000 + "\n";
log.debug("Graphite Message: {}", line);
writer.write(line);
} else {
onlyOnceLogger.infoOnce("Unable to submit non-numeric value to Graphite: [{}] from result [{}]", value, result);
}
}
} finally {
if (writer != null && writer.checkError()) {
log.error("Error writing to Graphite, clearing Graphite socket pool");
pool.invalidateObject(address, socket);
} else {
pool.returnObject(address, socket);
}
}
}
代码示例来源:origin: spring-projects/spring-session
@Test
public void printWriterCheckError() throws Exception {
boolean expected = true;
given(this.writer.checkError()).willReturn(expected);
assertThat(this.response.getWriter().checkError()).isEqualTo(expected);
}
代码示例来源:origin: org.apache.ant/ant
if (out.checkError()) {
throw new IOException(
"Encountered an error writing Ant structure");
代码示例来源:origin: cmusphinx/sphinx4
pw.println(path);
pw.print(path);
assertFalse(pw.checkError());
pw.close();
内容来源于网络,如有侵权,请联系作者删除!