Search in sources :

Example 11 with PrintWriter

use of java.io.PrintWriter in project groovy by apache.

the class MultipleCompilationErrorsException method getMessage.

public String getMessage() {
    StringWriter data = new StringWriter();
    PrintWriter writer = new PrintWriter(data);
    Janitor janitor = new Janitor();
    writer.write(super.getMessage());
    writer.println(":");
    try {
        collector.write(writer, janitor);
    } finally {
        janitor.cleanup();
    }
    return data.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 12 with PrintWriter

use of java.io.PrintWriter in project groovy by apache.

the class Groovyc method runCompiler.

private void runCompiler(String[] commandLine) {
    // hand crank it so we can add our own compiler configuration
    try {
        Options options = FileSystemCompiler.createCompilationOptions();
        CommandLineParser cliParser = new DefaultParser();
        CommandLine cli;
        cli = cliParser.parse(options, commandLine);
        configuration = FileSystemCompiler.generateCompilerConfigurationFromOptions(cli);
        configuration.setScriptExtensions(getScriptExtensions());
        String tmpExtension = getScriptExtension();
        if (tmpExtension.startsWith("*."))
            tmpExtension = tmpExtension.substring(1);
        configuration.setDefaultScriptExtension(tmpExtension);
        // Load the file name list
        String[] filenames = FileSystemCompiler.generateFileNamesFromOptions(cli);
        boolean fileNameErrors = filenames == null;
        fileNameErrors = fileNameErrors || !FileSystemCompiler.validateFiles(filenames);
        if (targetBytecode != null) {
            configuration.setTargetBytecode(targetBytecode);
        }
        if (!fileNameErrors) {
            FileSystemCompiler.doCompilation(configuration, makeCompileUnit(), filenames, forceLookupUnnamedFiles);
        }
    } catch (Exception re) {
        Throwable t = re;
        if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
            // unwrap to the real exception
            t = re.getCause();
        }
        StringWriter writer = new StringWriter();
        new ErrorReporter(t, false).write(new PrintWriter(writer));
        String message = writer.toString();
        taskSuccess = false;
        if (errorProperty != null) {
            getProject().setNewProperty(errorProperty, "true");
        }
        if (failOnError) {
            log.error(message);
            throw new BuildException("Compilation Failed", t, getLocation());
        } else {
            log.error(message);
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) CommandLine(org.apache.commons.cli.CommandLine) ErrorReporter(org.codehaus.groovy.tools.ErrorReporter) StringWriter(java.io.StringWriter) CommandLineParser(org.apache.commons.cli.CommandLineParser) BuildException(org.apache.tools.ant.BuildException) DefaultParser(org.apache.commons.cli.DefaultParser) PrintWriter(java.io.PrintWriter)

Example 13 with PrintWriter

use of java.io.PrintWriter in project groovy by apache.

the class Groovy method processError.

private void processError(Exception e) {
    StringWriter writer = new StringWriter();
    new ErrorReporter(e, false).write(new PrintWriter(writer));
    String message = writer.toString();
    throw new BuildException("Script Failed: " + message, e, getLocation());
}
Also used : ErrorReporter(org.codehaus.groovy.tools.ErrorReporter) StringWriter(java.io.StringWriter) BuildException(org.apache.tools.ant.BuildException) PrintWriter(java.io.PrintWriter)

Example 14 with PrintWriter

use of java.io.PrintWriter in project hadoop by apache.

the class TestFileUtil method createFile.

/**
   * Creates a new file in the specified directory, with the specified name and
   * the specified file contents.  This method will add a newline terminator to
   * the end of the contents string in the destination file.
   * @param directory File non-null destination directory.
   * @param name String non-null file name.
   * @param contents String non-null file contents.
   * @throws IOException if an I/O error occurs.
   */
private File createFile(File directory, String name, String contents) throws IOException {
    File newFile = new File(directory, name);
    PrintWriter pw = new PrintWriter(newFile);
    try {
        pw.println(contents);
    } finally {
        pw.close();
    }
    return newFile;
}
Also used : JarFile(java.util.jar.JarFile) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 15 with PrintWriter

use of java.io.PrintWriter in project flink by apache.

the class CommonTestUtils method printLog4jDebugConfig.

public static void printLog4jDebugConfig(File file) throws IOException {
    try (PrintWriter writer = new PrintWriter(new FileWriter(file))) {
        writer.println("log4j.rootLogger=DEBUG, console");
        writer.println("log4j.appender.console=org.apache.log4j.ConsoleAppender");
        writer.println("log4j.appender.console.target = System.err");
        writer.println("log4j.appender.console.layout=org.apache.log4j.PatternLayout");
        writer.println("log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n");
        writer.println("log4j.logger.org.eclipse.jetty.util.log=OFF");
        writer.println("log4j.logger.org.apache.zookeeper=OFF");
        writer.flush();
    }
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)3529 StringWriter (java.io.StringWriter)1062 IOException (java.io.IOException)653 File (java.io.File)532 Test (org.junit.Test)432 FileOutputStream (java.io.FileOutputStream)293 FileWriter (java.io.FileWriter)274 OutputStreamWriter (java.io.OutputStreamWriter)255 BufferedReader (java.io.BufferedReader)180 ArrayList (java.util.ArrayList)171 HttpServletResponse (javax.servlet.http.HttpServletResponse)141 ByteArrayOutputStream (java.io.ByteArrayOutputStream)139 FastPrintWriter (com.android.internal.util.FastPrintWriter)124 InputStreamReader (java.io.InputStreamReader)123 HttpServletRequest (javax.servlet.http.HttpServletRequest)121 Date (java.util.Date)120 HashMap (java.util.HashMap)113 Map (java.util.Map)106 BufferedWriter (java.io.BufferedWriter)105 Writer (java.io.Writer)87