Search in sources :

Example 56 with PrintWriter

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());
    }
}
Also used : IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 57 with PrintWriter

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();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 58 with PrintWriter

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();
}
Also used : PrintWriter(java.io.PrintWriter)

Example 59 with PrintWriter

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();
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 60 with PrintWriter

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);
}
Also used : Properties(java.util.Properties) SentencesAnnotation(edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation) CoreAnnotation(edu.stanford.nlp.ling.CoreAnnotation) Annotation(edu.stanford.nlp.pipeline.Annotation) TreeAnnotation(edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) TreeCoreAnnotations(edu.stanford.nlp.trees.TreeCoreAnnotations) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) CorefCoreAnnotations(edu.stanford.nlp.coref.CorefCoreAnnotations) TreeAnnotation(edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation) CoreMap(edu.stanford.nlp.util.CoreMap) 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