Search in sources :

Example 41 with PrintWriter

use of java.io.PrintWriter in project commons by twitter.

the class Configuration method store.

void store(Writer output, String message) {
    PrintWriter writer = new PrintWriter(output);
    writer.printf("# %s\n", new Date());
    writer.printf("# %s\n ", message);
    writer.println();
    for (ArgInfo info : positionalInfos) {
        writer.printf("positional %s %s\n", info.className, info.fieldName);
    }
    writer.println();
    for (ArgInfo info : cmdLineInfos) {
        writer.printf("field %s %s\n", info.className, info.fieldName);
    }
    writer.println();
    for (ParserInfo info : parserInfos) {
        writer.printf("parser %s %s\n", info.parsedType, info.parserClass);
    }
    writer.println();
    for (VerifierInfo info : verifierInfos) {
        writer.printf("verifier %s %s %s\n", info.verifiedType, info.verifyingAnnotation, info.verifierClass);
    }
}
Also used : Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 42 with PrintWriter

use of java.io.PrintWriter in project commons by twitter.

the class LogPrinter method doPost.

/**
   * A POST request is made from javascript, to request the contents of a log file.  In order to
   * fulfill the request, the 'file' parameter must be set in the request.
   *
   * If file starts with a '/' then the file parameter will be treated as an absolute file path.
   * If file does not start with a '/' then the path will be assumed to be
   * relative to the log directory.
   *
   * @param req Servlet request.
   * @param resp Servlet response.
   * @throws ServletException If there is a problem with the servlet.
   * @throws IOException If there is a problem reading/writing data to the client.
   */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/xml; charset=utf-8");
    try {
        LogViewRequest request = new LogViewRequest(req);
        if (request.file == null) {
            // The log file is a required parameter for POST requests.
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        resp.setStatus(HttpServletResponse.SC_OK);
        PrintWriter responseBody = resp.getWriter();
        String responseXml = fetchXmlLogContents(request);
        responseBody.write(responseXml);
        responseBody.close();
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Unknown exception.", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
Also used : ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter)

Example 43 with PrintWriter

use of java.io.PrintWriter in project commons by twitter.

the class TextResponseHandler method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(textContentType);
    resp.setStatus(HttpServletResponse.SC_OK);
    PrintWriter responseBody = resp.getWriter();
    for (String line : getLines(req)) {
        responseBody.println(line);
    }
    responseBody.close();
}
Also used : PrintWriter(java.io.PrintWriter)

Example 44 with PrintWriter

use of java.io.PrintWriter in project skype-bot by toomasr.

the class Help method reactInternal.

@Override
protected String reactInternal(String conversationName, String author, String message) {
    StringWriter out = new StringWriter();
    PrintWriter writer = new PrintWriter(out);
    writer.println("Available commands:");
    Commands.getCommandsHelp(writer);
    writer.flush();
    return out.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 45 with PrintWriter

use of java.io.PrintWriter in project watson by totemo.

the class SimpleFormatter method format.

// --------------------------------------------------------------------------
/**
   * Format the LogRecord.
   * 
   * @param log the record to format.
   */
@Override
public String format(LogRecord log) {
    StringBuilder builder = new StringBuilder();
    builder.append(_timeFormat.format(Long.valueOf(log.getMillis())));
    builder.append(" [");
    builder.append(log.getLevel().getName());
    builder.append("] ");
    builder.append(log.getMessage());
    builder.append('\n');
    Throwable thrown = log.getThrown();
    if (thrown != null) {
        StringWriter stringwriter = new StringWriter();
        thrown.printStackTrace(new PrintWriter(stringwriter));
        builder.append(stringwriter.toString());
    }
    return builder.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)4039 StringWriter (java.io.StringWriter)1201 IOException (java.io.IOException)788 File (java.io.File)643 Test (org.junit.Test)512 FileWriter (java.io.FileWriter)318 FileOutputStream (java.io.FileOutputStream)313 OutputStreamWriter (java.io.OutputStreamWriter)278 BufferedReader (java.io.BufferedReader)202 ArrayList (java.util.ArrayList)196 ByteArrayOutputStream (java.io.ByteArrayOutputStream)162 HttpServletResponse (javax.servlet.http.HttpServletResponse)145 InputStreamReader (java.io.InputStreamReader)140 Date (java.util.Date)131 HashMap (java.util.HashMap)130 ServletException (javax.servlet.ServletException)126 BufferedWriter (java.io.BufferedWriter)125 HttpServletRequest (javax.servlet.http.HttpServletRequest)125 FastPrintWriter (com.android.internal.util.FastPrintWriter)124 Map (java.util.Map)118