use of java.io.PrintWriter in project bazel by bazelbuild.
the class PrintingEventHandler method handle.
/**
* Print a description of the specified event to the appropriate
* output or error stream.
*/
@Override
public void handle(Event event) {
if (!getEventMask().contains(event.getKind())) {
return;
}
try {
switch(event.getKind()) {
case STDOUT:
outErr.getOutputStream().write(event.getMessageBytes());
outErr.getOutputStream().flush();
break;
case STDERR:
outErr.getErrorStream().write(event.getMessageBytes());
outErr.getErrorStream().flush();
break;
default:
PrintWriter err = new PrintWriter(outErr.getErrorStream());
err.print(event.getKind());
err.print(": ");
if (event.getLocation() != null) {
err.print(event.getLocation().print());
err.print(": ");
}
err.println(event.getMessage());
err.flush();
}
} catch (IOException e) {
/*
* Note: we can't print to System.out or System.err here,
* because those will normally be set to streams which
* translate I/O to STDOUT and STDERR events,
* which would result in infinite recursion.
*/
outErr.printErrLn(e.getMessage());
}
}
use of java.io.PrintWriter in project bigbluebutton by bigbluebutton.
the class StackTraceUtil method getStackTrace.
public static String getStackTrace(Throwable aThrowable) {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
aThrowable.printStackTrace(printWriter);
return result.toString();
}
use of java.io.PrintWriter in project CoreNLP by stanfordnlp.
the class Counters method serializeStringCounter.
/**
* Serialize a counter into an efficient string TSV
* @param c The counter to serialize
* @param filename The file to serialize to
* @param minMagnitude Ignore values under this magnitude
* @throws IOException
*
* @see Counters#deserializeStringCounter(String)
*/
public static void serializeStringCounter(Counter<String> c, String filename, double minMagnitude) throws IOException {
PrintWriter writer = IOUtils.getPrintWriter(filename);
for (Entry<String, Double> entry : c.entrySet()) {
if (Math.abs(entry.getValue()) < minMagnitude) {
continue;
}
Triple<Boolean, Long, Integer> parts = SloppyMath.segmentDouble(entry.getValue());
writer.println(entry.getKey().replace('\t', 'ߝ') + "\t" + (parts.first ? '-' : '+') + "\t" + parts.second + "\t" + parts.third);
}
writer.close();
}
use of java.io.PrintWriter in project CoreNLP by stanfordnlp.
the class Counters method save2DCounterSorted.
public static <T1, T2> void save2DCounterSorted(TwoDimensionalCounterInterface<T1, T2> tdc, String filename) throws IOException {
PrintWriter out = new PrintWriter(new FileWriter(filename));
for (T1 outer : tdc.firstKeySet()) {
Counter<T2> c = tdc.getCounter(outer);
List<T2> keys = Counters.toSortedList(c);
for (T2 inner : keys) {
out.println(outer + "\t" + inner + '\t' + c.getCount(inner));
}
}
out.close();
}
use of java.io.PrintWriter in project CoreNLP by stanfordnlp.
the class CoNLLDocumentReader method main.
/** Reads and dumps output, mainly for debugging. */
public static void main(String[] args) throws IOException {
Properties props = StringUtils.argsToProperties(args);
boolean debug = false;
String filepath = props.getProperty("i");
String outfile = props.getProperty("o");
if (filepath == null || outfile == null) {
usage();
System.exit(-1);
}
PrintWriter fout = new PrintWriter(outfile);
logger.info("Writing to " + outfile);
String ext = props.getProperty("ext");
Options options;
if (ext != null) {
options = new Options(".*" + ext + "$");
} else {
options = new Options();
}
options.annotateTreeCoref = true;
options.annotateTreeNer = true;
CorpusStats corpusStats = new CorpusStats();
CoNLLDocumentReader reader = new CoNLLDocumentReader(filepath, options);
int docCnt = 0;
int sentCnt = 0;
int tokenCnt = 0;
for (CoNLLDocument doc; (doc = reader.getNextDocument()) != null; ) {
corpusStats.process(doc);
docCnt++;
Annotation anno = doc.getAnnotation();
if (debug)
System.out.println("Document " + docCnt + ": " + anno.get(CoreAnnotations.DocIDAnnotation.class));
for (CoreMap sentence : anno.get(CoreAnnotations.SentencesAnnotation.class)) {
if (debug)
System.out.println("Parse: " + sentence.get(TreeCoreAnnotations.TreeAnnotation.class));
if (debug)
System.out.println("Sentence Tokens: " + StringUtils.join(sentence.get(CoreAnnotations.TokensAnnotation.class), ","));
writeTabSep(fout, sentence, doc.corefChainMap);
sentCnt++;
tokenCnt += sentence.get(CoreAnnotations.TokensAnnotation.class).size();
}
if (debug) {
for (CoreMap ner : doc.nerChunks) {
System.out.println("NER Chunk: " + ner);
}
for (String id : doc.corefChainMap.keySet()) {
System.out.println("Coref: " + id + " = " + StringUtils.join(doc.corefChainMap.get(id), ";"));
}
}
}
fout.close();
System.out.println("Total document count: " + docCnt);
System.out.println("Total sentence count: " + sentCnt);
System.out.println("Total token count: " + tokenCnt);
System.out.println(corpusStats);
}
Aggregations