Search in sources :

Example 81 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project sling by apache.

the class MetricWebConsolePlugin method print.

//~--------------------------------------------< InventoryPrinter >
@Override
public void print(PrintWriter printWriter, Format format, boolean isZip) {
    if (format == Format.TEXT) {
        MetricRegistry registry = getConsolidatedRegistry();
        ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).outputTo(new PrintStream(new WriterOutputStream(printWriter))).build();
        reporter.report();
        reporter.close();
    } else if (format == Format.JSON) {
        MetricRegistry registry = getConsolidatedRegistry();
        JSONReporter reporter = JSONReporter.forRegistry(registry).outputTo(new PrintStream(new WriterOutputStream(printWriter))).build();
        reporter.report();
        reporter.close();
    }
}
Also used : PrintStream(java.io.PrintStream) ConsoleReporter(com.codahale.metrics.ConsoleReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 82 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project abstools by abstools.

the class ClassGenerator method generateRecoverHandler.

private void generateRecoverHandler() {
    if (classDecl.hasRecoverBranch()) {
        Vars vars = new Vars();
        Vars safe = vars.pass();
        // Build var scopes and statmemnts for each branch
        java.util.List<Vars> branches_vars = new java.util.LinkedList<>();
        java.util.List<String> branches = new java.util.LinkedList<>();
        for (CaseBranchStmt b : classDecl.getRecoverBranchs()) {
            Vars v = vars.pass();
            StringWriter sw = new StringWriter();
            CodeStream buffer = new CodeStream(new WriterOutputStream(sw, Charset.forName("UTF-8")), "");
            b.getLeft().generateErlangCode(ecs, buffer, v);
            buffer.setIndent(ecs.getIndent());
            buffer.println("->");
            buffer.incIndent();
            b.getRight().generateErlangCode(buffer, v);
            buffer.println(",");
            buffer.print("true");
            buffer.decIndent();
            buffer.close();
            branches_vars.add(v);
            branches.add(sw.toString());
            vars.updateTemp(v);
        }
        ErlUtil.functionHeader(ecs, "recover", ErlUtil.Mask.none, generatorClassMatcher(), "Exception");
        ecs.println("Result=case Exception of ");
        ecs.incIndent();
        // Now print statments and mergelines for each branch.
        java.util.List<String> mergeLines = vars.merge(branches_vars);
        Iterator<String> ib = branches.iterator();
        Iterator<String> im = mergeLines.iterator();
        while (ib.hasNext()) {
            ecs.print(ib.next());
            ecs.incIndent();
            ecs.print(im.next());
            ecs.println(";");
            ecs.decIndent();
        }
        ecs.println("_ -> false");
        ecs.decIndent();
        ecs.print("end");
        ecs.println(".");
        ecs.decIndent();
    }
}
Also used : CodeStream(abs.backend.common.CodeStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 83 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project jackrabbit-oak by apache.

the class Segment method toString.

// ------------------------------------------------------------< Object >--
@Override
public String toString() {
    StringWriter string = new StringWriter();
    try (PrintWriter writer = new PrintWriter(string)) {
        writer.format("Segment %s (%d bytes)%n", id, data.size());
        String segmentInfo = getSegmentInfo();
        if (segmentInfo != null) {
            writer.format("Info: %s, Generation: %s%n", segmentInfo, getGcGeneration());
        }
        if (id.isDataSegmentId()) {
            writer.println("--------------------------------------------------------------------------");
            int i = 1;
            for (SegmentId segmentId : segmentReferences) {
                writer.format("reference %02x: %s%n", i++, segmentId);
            }
            for (Entry entry : recordNumbers) {
                int offset = entry.getOffset();
                int address = data.size() - (MAX_SEGMENT_SIZE - offset);
                writer.format("%10s record %08x: %08x @ %08x%n", entry.getType(), entry.getRecordNumber(), offset, address);
            }
        }
        writer.println("--------------------------------------------------------------------------");
        try {
            data.hexDump(new WriterOutputStream(writer, Charsets.UTF_8));
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        writer.println("--------------------------------------------------------------------------");
    }
    return string.toString();
}
Also used : Entry(org.apache.jackrabbit.oak.segment.RecordNumbers.Entry) StringWriter(java.io.StringWriter) SegmentId.isDataSegmentId(org.apache.jackrabbit.oak.segment.SegmentId.isDataSegmentId) IOException(java.io.IOException) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) PrintWriter(java.io.PrintWriter)

Example 84 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project jackrabbit-oak by apache.

the class IndexConsistencyCheckPrinter method print.

@Override
public void print(PrintWriter pw, Format format, boolean isZip) {
    Stopwatch watch = Stopwatch.createStarted();
    NodeState root = indexHelper.getNodeStore().getRoot();
    List<String> validIndexes = new ArrayList<>();
    List<String> invalidIndexes = new ArrayList<>();
    List<String> ignoredIndexes = new ArrayList<>();
    for (String indexPath : indexHelper.getIndexPathService().getIndexPaths()) {
        NodeState indexState = NodeStateUtils.getNode(root, indexPath);
        if (!TYPE_LUCENE.equals(indexState.getString(TYPE_PROPERTY_NAME))) {
            ignoredIndexes.add(indexPath);
            continue;
        }
        IndexConsistencyChecker checker = new IndexConsistencyChecker(root, indexPath, indexHelper.getWorkDir());
        checker.setPrintStream(new PrintStream(new WriterOutputStream(pw, Charsets.UTF_8)));
        try {
            IndexConsistencyChecker.Result result = checker.check(level);
            result.dump(pw);
            if (result.clean) {
                validIndexes.add(indexPath);
            } else {
                invalidIndexes.add(indexPath);
            }
            System.out.printf("%s => %s%n", indexPath, result.clean ? "valid" : "invalid <==");
        } catch (Exception e) {
            invalidIndexes.add(indexPath);
            pw.printf("Error occurred while performing consistency check for index [%s]%n", indexPath);
            e.printStackTrace(pw);
        }
        pw.println();
    }
    print(validIndexes, "Valid indexes :", pw);
    print(invalidIndexes, "Invalid indexes :", pw);
    print(ignoredIndexes, "Ignored indexes as these are not of type lucene:", pw);
    pw.printf("Time taken %s%n", watch);
}
Also used : PrintStream(java.io.PrintStream) IndexConsistencyChecker(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) IOException(java.io.IOException)

Example 85 with WriterOutputStream

use of org.apache.commons.io.output.WriterOutputStream in project rest-assured by rest-assured.

the class LoggingIfValidationFailsTest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging.

@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging() {
    final StringWriter writer = new StringWriter();
    final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
    RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
    RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().setConfig(config().logConfig(new LogConfig(captor, true))).addHeader("Api-Key", "1234").build();
    RestAssuredMockMvc.enableLoggingOfRequestAndResponseIfValidationFails(HEADERS);
    try {
        given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
        fail("Should throw AssertionError");
    } catch (AssertionError e) {
        assertThat(writer.toString(), equalTo("Headers:\t\tApi-Key=1234\n\t\t\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\n\nContent-Type: application/json;charset=UTF-8\n"));
    }
}
Also used : PrintStream(java.io.PrintStream) PostController(io.restassured.module.mockmvc.http.PostController) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) StringWriter(java.io.StringWriter) ResponseSpecBuilder(io.restassured.builder.ResponseSpecBuilder) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) LogConfig(io.restassured.config.LogConfig) Test(org.junit.Test)

Aggregations

WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)159 StringWriter (java.io.StringWriter)150 PrintStream (java.io.PrintStream)141 Test (org.junit.Test)133 LogConfig (io.restassured.config.LogConfig)46 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)44 ResponseBuilder (io.restassured.builder.ResponseBuilder)36 Filter (io.restassured.filter.Filter)35 FilterContext (io.restassured.filter.FilterContext)35 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)35 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)35 OutputStream (java.io.OutputStream)8 IOException (java.io.IOException)7 Col (org.apache.karaf.shell.table.Col)6 ShellTable (org.apache.karaf.shell.table.ShellTable)6 InputStream (java.io.InputStream)5 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)4 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 ScalatraObject (io.restassured.itest.java.objects.ScalatraObject)3