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);
}
}
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);
}
}
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();
}
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();
}
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();
}
Aggregations