Search in sources :

Example 76 with OutputStreamWriter

use of java.io.OutputStreamWriter in project jslint4java by happygiraffe.

the class ReportResultFormatter method end.

public void end() {
    if (formatter.footer() != null) {
        sb.append(formatter.footer());
    }
    Writer w = null;
    try {
        w = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
        w.write(sb.toString());
        w.flush();
    } catch (IOException exc) {
        throw new BuildException("Unable to write log file", exc);
    } finally {
        FileUtils.close(w);
    }
    out = null;
    sb.delete(0, sb.length() - 1);
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 77 with OutputStreamWriter

use of java.io.OutputStreamWriter in project HanLP by hankcs.

the class TMDictionaryMaker method saveTxtTo.

@Override
public boolean saveTxtTo(String path) {
    try {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path)));
        bw.write(toString());
        bw.close();
    } catch (Exception e) {
        logger.warning("在保存转移矩阵词典到" + path + "时发生异常" + e);
        return false;
    }
    return true;
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 78 with OutputStreamWriter

use of java.io.OutputStreamWriter in project jslint4java by happygiraffe.

the class ReportWriterImpl method open.

public void open() {
    try {
        Files.createParentDirs(reportFile);
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(reportFile), Charset.forName("UTF-8")));
        if (formatter.header() != null) {
            writer.write(formatter.header());
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 79 with OutputStreamWriter

use of java.io.OutputStreamWriter in project gradle by gradle.

the class ConsoleConfigureAction method execute.

public void execute(OutputEventRenderer renderer, ConsoleOutput consoleOutput) {
    if (consoleOutput == ConsoleOutput.Plain) {
        return;
    }
    ConsoleDetector consoleDetector = NativeServices.getInstance().get(ConsoleDetector.class);
    ConsoleMetaData consoleMetaData = consoleDetector.getConsole();
    boolean force = false;
    if (consoleMetaData == null) {
        if (consoleOutput == ConsoleOutput.Auto) {
            return;
        }
        assert consoleOutput == ConsoleOutput.Rich;
        consoleMetaData = new FallbackConsoleMetaData();
        force = true;
    }
    boolean stdOutIsTerminal = consoleMetaData.isStdOut();
    boolean stdErrIsTerminal = consoleMetaData.isStdErr();
    int numWorkersToDisplay = ConsoleLayoutCalculator.calculateNumWorkersForConsoleDisplay(consoleMetaData);
    if (stdOutIsTerminal) {
        OutputStream originalStdOut = renderer.getOriginalStdOut();
        OutputStreamWriter outStr = new OutputStreamWriter(force ? originalStdOut : AnsiConsoleUtil.wrapOutputStream(originalStdOut));
        Console console = new AnsiConsole(outStr, outStr, renderer.getColourMap(), consoleMetaData, numWorkersToDisplay, force);
        renderer.addConsole(console, true, stdErrIsTerminal, consoleMetaData);
    } else if (stdErrIsTerminal) {
        // Only stderr is connected to a terminal
        OutputStream originalStdErr = renderer.getOriginalStdErr();
        OutputStreamWriter errStr = new OutputStreamWriter(force ? originalStdErr : AnsiConsoleUtil.wrapOutputStream(originalStdErr));
        Console console = new AnsiConsole(errStr, errStr, renderer.getColourMap(), consoleMetaData, numWorkersToDisplay, force);
        renderer.addConsole(console, false, true, consoleMetaData);
    }
}
Also used : FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleDetector(org.gradle.internal.nativeintegration.console.ConsoleDetector) OutputStream(java.io.OutputStream) Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleMetaData(org.gradle.internal.nativeintegration.console.ConsoleMetaData) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole)

Example 80 with OutputStreamWriter

use of java.io.OutputStreamWriter in project gradle by gradle.

the class OutputEventRenderer method attachAnsiConsole.

public void attachAnsiConsole(OutputStream outputStream) {
    synchronized (lock) {
        ConsoleMetaData consoleMetaData = new FallbackConsoleMetaData();
        OutputStreamWriter writer = new OutputStreamWriter(outputStream);
        int numWorkersToDisplay = ConsoleLayoutCalculator.calculateNumWorkersForConsoleDisplay(consoleMetaData);
        Console console = new AnsiConsole(writer, writer, colourMap, consoleMetaData, numWorkersToDisplay, true);
        addConsole(console, true, true, consoleMetaData);
    }
}
Also used : FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) Console(org.gradle.internal.logging.console.Console) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole) FallbackConsoleMetaData(org.gradle.internal.nativeintegration.console.FallbackConsoleMetaData) ConsoleMetaData(org.gradle.internal.nativeintegration.console.ConsoleMetaData) OutputStreamWriter(java.io.OutputStreamWriter) AnsiConsole(org.gradle.internal.logging.console.AnsiConsole)

Aggregations

OutputStreamWriter (java.io.OutputStreamWriter)1784 IOException (java.io.IOException)690 FileOutputStream (java.io.FileOutputStream)653 BufferedWriter (java.io.BufferedWriter)647 Writer (java.io.Writer)479 File (java.io.File)407 PrintWriter (java.io.PrintWriter)296 InputStreamReader (java.io.InputStreamReader)244 OutputStream (java.io.OutputStream)221 ByteArrayOutputStream (java.io.ByteArrayOutputStream)216 BufferedReader (java.io.BufferedReader)210 Test (org.junit.Test)129 InputStream (java.io.InputStream)112 FileNotFoundException (java.io.FileNotFoundException)104 ArrayList (java.util.ArrayList)96 Path (org.apache.hadoop.fs.Path)93 UnsupportedEncodingException (java.io.UnsupportedEncodingException)92 URL (java.net.URL)90 HttpURLConnection (java.net.HttpURLConnection)78 FileInputStream (java.io.FileInputStream)71