public boolean checkError() { return getResponseWriter().checkError(); } public void close() {
@Override public boolean checkError() { return this.delegate.checkError(); }
/** 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(); } } }
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; } } } }
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; } } } }
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 ... }
/** * 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"); } } }
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); }
/** * 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; }
/** * 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); } } }
@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); } } }
@Override public void run() boolean outError = out != null ? out.checkError() : false; if ( out.checkError() )
while (!writer.checkError() && !isBrokenRef.get() && !Thread.currentThread().isInterrupted()) {
if (writer.checkError()) { throw new IOException("Encountered an error writing tagdiff");
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); }
if (writer.checkError()) { throw new IOException("Encountered an error writing jar index");
@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); } } }
@Test public void printWriterCheckError() throws Exception { boolean expected = true; given(this.writer.checkError()).willReturn(expected); assertThat(this.response.getWriter().checkError()).isEqualTo(expected); }
if (out.checkError()) { throw new IOException( "Encountered an error writing Ant structure");
pw.println(path); pw.print(path); assertFalse(pw.checkError()); pw.close();