Search in sources :

Example 46 with PrintWriter

use of java.io.PrintWriter in project adt4j by sviperll.

the class Throwables method render.

public static String render(Throwable exception) {
    StringWriter message = new StringWriter();
    PrintWriter writer = new PrintWriter(message);
    exception.printStackTrace(writer);
    writer.flush();
    return message.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 47 with PrintWriter

use of java.io.PrintWriter in project playn by threerings.

the class IOSLog method logImpl.

@Override
protected void logImpl(Level level, String msg, Throwable e) {
    Console.WriteLine(level + ": " + msg);
    if (e != null) {
        try {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            Console.WriteLine(sw.toString());
        } catch (Throwable t) {
            Console.WriteLine(e);
            Console.WriteLine("<stack trace generation failed: " + t + ">");
        }
    }
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 48 with PrintWriter

use of java.io.PrintWriter in project bazel by bazelbuild.

the class BazelBuildCaseTest method testPrepareGeneratedCode_Copy.

@Test
public void testPrepareGeneratedCode_Copy() throws IOException {
    Path root = folder.newFolder("PrepareGeneratedCodeCopy").toPath();
    // Prepare source
    Path source = root.resolve("source");
    source.toFile().mkdir();
    try (PrintWriter writer = new PrintWriter(source.resolve("file").toFile(), UTF_8.name())) {
        writer.println("content");
    }
    // Prepare destination
    Path destination = root.resolve("destination");
    destination.toFile().mkdir();
    new BazelBuildCase().prepareGeneratedCode(source, destination);
    ImmutableSet<String> filenames = fileArrayToImmutableSet(destination.toFile().listFiles());
    assertThat(filenames).containsExactly("WORKSPACE", "file");
    assertThat(new Scanner(destination.resolve("file")).useDelimiter("\\Z").next()).isEqualTo("content");
}
Also used : Path(java.nio.file.Path) Scanner(java.util.Scanner) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 49 with PrintWriter

use of java.io.PrintWriter in project bazel by bazelbuild.

the class BazelBuilderTest method testBuildAndGetElapsedTime.

@Test
public void testBuildAndGetElapsedTime() throws IOException, CommandException {
    Path root = folder.newFolder("BuildAndGetElapsedTime").toPath();
    Path generatedCode = root.resolve("GeneratedCode");
    Files.createDirectories(generatedCode);
    // Prepare binary
    Path buildBinary = root.resolve("binary.sh");
    Files.createFile(buildBinary);
    if (!buildBinary.toFile().setExecutable(true)) {
        fail("Failed to set executable");
    }
    double expectedValue = 10.42;
    try (PrintWriter writer = new PrintWriter(buildBinary.toFile())) {
        writer.format("#!/bin/bash\n>&2 echo 'blah blah Elapsed time: %.2f blah blah'", expectedValue);
    }
    double result = new BazelBuilder(generatedCode, null).buildAndGetElapsedTime(buildBinary, ImmutableList.<String>of());
    assertThat(result).isWithin(EPSILON).of(expectedValue);
}
Also used : Path(java.nio.file.Path) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 50 with PrintWriter

use of java.io.PrintWriter in project disunity by ata4.

the class DisUnityCli method main.

/**
     * @param args the command line arguments
     */
public static void main(String[] args) {
    LogUtils.configure();
    try (PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true)) {
        JCommander jc = new JCommander();
        DisUnityRoot root = new DisUnityRoot();
        root.init(jc, out);
        jc.setProgramName(DisUnity.getProgramName());
        jc.addObject(root);
        jc.parse(args);
        root.run();
    } catch (ParameterException ex) {
        L.log(Level.WARNING, "Parameter error: {0}", ex.getMessage());
    } catch (Throwable t) {
        L.log(Level.SEVERE, "Fatal error", t);
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) OutputStreamWriter(java.io.OutputStreamWriter) ParameterException(com.beust.jcommander.ParameterException) DisUnityRoot(info.ata4.disunity.cli.command.DisUnityRoot) 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