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