use of java.io.PrintWriter in project flink by apache.
the class TestLogger method exceptionToString.
private static String exceptionToString(Throwable t) {
if (t == null) {
return "(null)";
}
try {
StringWriter stm = new StringWriter();
PrintWriter wrt = new PrintWriter(stm);
t.printStackTrace(wrt);
wrt.close();
return stm.toString();
} catch (Throwable ignored) {
return t.getClass().getName() + " (error while printing stack trace)";
}
}
use of java.io.PrintWriter in project hadoop by apache.
the class ReconfigurationServlet method doPost.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
LOG.info("POST");
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
Reconfigurable reconf = getReconfigurable(req);
String nodeName = reconf.getClass().getCanonicalName();
printHeader(out, nodeName);
try {
applyChanges(out, reconf, req);
} catch (ReconfigurationException e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, StringUtils.stringifyException(e));
return;
}
out.println("<p><a href=\"" + req.getServletPath() + "\">back</a></p>");
printFooter(out);
}
use of java.io.PrintWriter in project groovy by apache.
the class JavaStubGenerator method generateClass.
public void generateClass(ClassNode classNode) throws FileNotFoundException {
// Only attempt to render our self if our super-class is resolved, else wait for it
if (requireSuperResolved && !classNode.getSuperClass().isResolved()) {
return;
}
// owner should take care for us
if (classNode instanceof InnerClassNode)
return;
// don't generate stubs for private classes, as they are only visible in the same file
if ((classNode.getModifiers() & Opcodes.ACC_PRIVATE) != 0)
return;
String fileName = classNode.getName().replace('.', '/');
mkdirs(outputPath, fileName);
toCompile.add(fileName);
File file = new File(outputPath, fileName + ".java");
FileOutputStream fos = new FileOutputStream(file);
Charset charset = Charset.forName(encoding);
PrintWriter out = new PrintWriter(new OutputStreamWriter(fos, charset));
try {
String packageName = classNode.getPackageName();
if (packageName != null) {
out.println("package " + packageName + ";\n");
}
printImports(out, classNode);
printClassContents(out, classNode);
} finally {
try {
out.close();
} catch (Exception e) {
// ignore
}
try {
fos.close();
} catch (IOException e) {
// ignore
}
}
}
use of java.io.PrintWriter in project groovy by apache.
the class JavacJavaCompiler method compile.
public void compile(List<String> files, CompilationUnit cu) {
String[] javacParameters = makeParameters(files, cu.getClassLoader());
StringWriter javacOutput = null;
int javacReturnValue = 0;
try {
Class javac = findJavac(cu);
Method method = null;
try {
method = javac.getMethod("compile", new Class[] { String[].class, PrintWriter.class });
javacOutput = new StringWriter();
PrintWriter writer = new PrintWriter(javacOutput);
Object ret = method.invoke(null, javacParameters, writer);
javacReturnValue = (Integer) ret;
} catch (NoSuchMethodException e) {
}
if (method == null) {
method = javac.getMethod("compile", new Class[] { String[].class });
Object ret = method.invoke(null, new Object[] { javacParameters });
javacReturnValue = (Integer) ret;
}
} catch (InvocationTargetException ite) {
cu.getErrorCollector().addFatalError(new ExceptionMessage((Exception) ite.getCause(), true, cu));
} catch (Exception e) {
cu.getErrorCollector().addFatalError(new ExceptionMessage(e, true, cu));
}
if (javacReturnValue != 0) {
switch(javacReturnValue) {
case 1:
addJavacError("Compile error during compilation with javac.", cu, javacOutput);
break;
case 2:
addJavacError("Invalid commandline usage for javac.", cu, javacOutput);
break;
case 3:
addJavacError("System error during compilation with javac.", cu, javacOutput);
break;
case 4:
addJavacError("Abnormal termination of javac.", cu, javacOutput);
break;
default:
addJavacError("unexpected return value by javac.", cu, javacOutput);
break;
}
} else {
// print warnings if any
System.out.print(javacOutput);
}
}
use of java.io.PrintWriter in project groovy by apache.
the class CSTNode method toString.
//---------------------------------------------------------------------------
// STRING CONVERSION
/**
* Formats the node as a <code>String</code> and returns it.
*/
public String toString() {
StringWriter string = new StringWriter();
write(new PrintWriter(string));
string.flush();
return string.toString();
}
Aggregations