Example usage for java.io OutputStreamWriter flush

List of usage examples for java.io OutputStreamWriter flush

Introduction

In this page you can find the example usage for java.io OutputStreamWriter flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:org.apiwatch.cli.APIDiff.java

public static void main(String[] argv) {
    try {/*from w w w  .ja  v a  2s. co  m*/
        Namespace args = parseArgs(argv);

        Logger log = Logger.getLogger(APIDiff.class.getName());

        @SuppressWarnings("unchecked")
        Map<String, Map<String, String>> rulesConfig = (Map<String, Map<String, String>>) args
                .get(Args.RULES_CONFIG_OPTION);
        if (rulesConfig != null) {
            RulesFinder.configureRules(rulesConfig);
        }

        log.trace("Deserializing API data...");
        APIScope scopeA = IO.getAPIData(args.getString(COMPONENT_A), args.getString(Args.INPUT_FORMAT_OPTION),
                args.getString(Analyser.ENCODING_OPTION), args.getString(Args.USERNAME_OPTION),
                args.getString(Args.PASSWORD_OPTION));
        APIScope scopeB = IO.getAPIData(args.getString(COMPONENT_B), args.getString(Args.INPUT_FORMAT_OPTION),
                args.getString(Analyser.ENCODING_OPTION), args.getString(Args.USERNAME_OPTION),
                args.getString(Args.PASSWORD_OPTION));

        log.trace("Calculation of differences...");
        List<APIDifference> diffs = DifferencesCalculator.getDiffs(scopeA, scopeB);

        log.trace("Detection of API stability violations...");
        ViolationsCalculator violationsClac = new ViolationsCalculator(RulesFinder.rules().values());

        Severity threshold = (Severity) args.get(Args.SEVERITY_THRESHOLD_OPTION);
        List<APIStabilityViolation> violations = violationsClac.getViolations(diffs, threshold);

        OutputStreamWriter writer = new OutputStreamWriter(System.out);
        Serializers.dumpViolations(violations, writer, args.getString(Args.OUTPUT_FORMAT_OPTION));
        writer.flush();
        writer.close();
    } catch (HttpException e) {
        Logger.getLogger(APIDiff.class.getName()).error(e.getMessage());
        System.exit(1);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

}

From source file:org.apiwatch.cli.APIWatch.java

public static void main(String[] argv) {
    try {/*  ww w.j  a  va 2s.co  m*/
        Namespace args = parseArgs(argv);

        Logger log = Logger.getLogger(APIWatch.class.getName());

        @SuppressWarnings("unchecked")
        Map<String, Map<String, String>> rulesConfig = (Map<String, Map<String, String>>) args
                .get(Args.RULES_CONFIG_OPTION);
        if (rulesConfig != null) {
            RulesFinder.configureRules(rulesConfig);
        }

        APIScope referenceScope = IO.getAPIData(args.getString(REFERENCE_API_DATA),
                args.getString(Args.INPUT_FORMAT_OPTION), args.getString(Analyser.ENCODING_OPTION),
                args.getString(Args.USERNAME_OPTION), args.getString(Args.PASSWORD_OPTION));

        DirectoryWalker walker = new DirectoryWalker(args.<String>getList(Args.EXCLUDES_OPTION),
                args.<String>getList(Args.INCLUDES_OPTION));

        Set<String> files = walker.walk(args.<String>getList(INPUT_PATHS));
        APIScope newScope = Analyser.analyse(files, args.getAttrs());

        log.trace("Calculation of differences...");
        List<APIDifference> diffs = DifferencesCalculator.getDiffs(referenceScope, newScope);

        log.trace("Detection of API stability violations...");
        ViolationsCalculator violationsClac = new ViolationsCalculator(RulesFinder.rules().values());

        Severity threshold = (Severity) args.get(Args.SEVERITY_THRESHOLD_OPTION);
        List<APIStabilityViolation> violations = violationsClac.getViolations(diffs, threshold);

        OutputStreamWriter writer = new OutputStreamWriter(System.out);
        Serializers.dumpViolations(violations, writer, args.getString(Args.OUTPUT_FORMAT_OPTION));
        writer.flush();
        writer.close();

        log.info(violations.size() + " violations.");
    } catch (HttpException e) {
        Logger.getLogger(APIWatch.class.getName()).error(e.getMessage());
        System.exit(1);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {/* www .  ja v a  2 s . c o m*/
        // create a new OutputStreamWriter
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();
        // read what we write
        System.out.println((char) in.read());
        writer.close();
        os.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {/*from   ww  w. j a va 2  s .  com*/
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();

        // read what we write
        System.out.println((char) in.read());

        // close the stream
        writer.close();
        os.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {/*from   w w w  . jav a2 s  .c  o  m*/
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();

        // get and print the encoding for this stream
        System.out.println(writer.getEncoding());

        // read what we write
        System.out.println((char) in.read());
        writer.close();
        os.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    char[] arr = { 'H', 'e', 'l', 'l', 'o' };

    try {/*from w  w  w  .  j  a  va 2 s.co  m*/

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(arr, 0, 3);

        // flush the stream
        writer.flush();

        // read what we write
        for (int i = 0; i < 3; i++) {
            System.out.print((char) in.read());
        }

        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.foudroyantfactotum.mod.fousarchive.utility.midi.FileSupporter.java

public static void main(String[] args) throws InterruptedException, IOException {
    for (int i = 0; i < noOfWorkers; ++i)
        pool.submit(new ConMidiDetailsPuller());

    final File sourceDir = new File(source);
    final File outputDir = new File(output);

    Logger.info(UserLogger.GENERAL, "source directory: " + sourceDir.getAbsolutePath());
    Logger.info(UserLogger.GENERAL, "output directory: " + outputDir.getAbsolutePath());
    Logger.info(UserLogger.GENERAL, "processing midi files using " + noOfWorkers + " cores");

    FileUtils.deleteDirectory(outputDir);
    FileUtils.touch(new File(outputDir + "/master.json.gz"));

    for (File sfile : sourceDir.listFiles()) {
        recFile(sfile, files);/*from   w w  w  . ja  v  a2s.c o m*/
    }

    for (int i = 0; i < noOfWorkers; ++i)
        files.put(TERMINATOR);

    pool.shutdown();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);//just get all the work done first.

    try (final OutputStream fstream = new FileOutputStream(outputDir + "/master.json.gz")) {
        try (final GZIPOutputStream gzstream = new GZIPOutputStream(fstream)) {
            final OutputStreamWriter osw = new OutputStreamWriter(gzstream);

            osw.write(JSON.toJson(processedMidiFiles));
            osw.flush();
        }
    } catch (IOException e) {
        Logger.info(UserLogger.GENERAL, e.toString());
    }

    Logger.info(UserLogger.GENERAL, "Processed " + processedMidiFiles.size() + " midi files out of " + fileCount
            + " files. " + (fileCount - processedMidiFiles.size()) + " removed");
}

From source file:Main.java

public static void main(String[] args) {
    try {//from w  w  w . j  a v  a  2s .  c o  m
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);
        writer.write(71);
        writer.write(72);

        // flush the stream
        writer.flush();

        // read what we write
        for (int i = 0; i < 3; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:lohbihler.process.Test.java

public static void main(final String[] args) throws Exception {
    final ExecutorService executorService = Executors.newCachedThreadPool();

    final Process process = new ProcessBuilder("cmd").start();
    final InputReader input = new InputReader(process.getInputStream());
    final InputReader error = new InputReader(process.getErrorStream());

    executorService.execute(input);//w w  w  . j a  v  a 2s.  co m
    executorService.execute(error);
    final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream());

    Thread.sleep(1000);
    System.out.println("Input: " + input.getInput());
    System.out.println("Error: " + error.getInput());
    System.out.println("Alive: " + process.isAlive());
    System.out.println();

    out.append("PING 1.1.1.1 -n 1 -w 5000\r\n");
    out.flush();

    for (int i = 0; i < 7; i++) {
        Thread.sleep(1000);
        System.out.println("Input: " + input.getInput());
        System.out.println("Error: " + error.getInput());
        System.out.println("Alive: " + process.isAlive());
        System.out.println();
    }

    out.append("PING 1.1.1.1 -n 1 -w 2000\r\n");
    out.flush();

    for (int i = 0; i < 4; i++) {
        Thread.sleep(1000);
        System.out.println("Input: " + input.getInput());
        System.out.println("Error: " + error.getInput());
        System.out.println("Alive: " + process.isAlive());
        System.out.println();
    }

    process.destroy();

    executorService.shutdown();
}

From source file:org.commoncrawl.service.parser.server.ParseWorker.java

public static void main(String[] args) throws IOException {
    String baseURL = "http://unknown.com/";
    NIOHttpHeaders headers = null;/*w  w w  .ja  va 2  s.  c  om*/
    if (args.length != 0) {
        for (int i = 0; i < args.length; ++i) {
            if (args[i].equalsIgnoreCase("--noHeaders")) {
                headers = new NIOHttpHeaders();
                headers.add("content-type", "text/html");
            } else if (args[i].equalsIgnoreCase("--baseURL")) {
                baseURL = args[++i];
            }
        }
    }
    URL baseURLObj;
    try {
        baseURLObj = new URL(baseURL);
    } catch (MalformedURLException e2) {
        LOG.error(CCStringUtils.stringifyException(e2));
        throw new IOException("Invalid Base Link");
    }

    final DataOutputBuffer headerBuffer = new DataOutputBuffer();
    final DataOutputBuffer contentBuffer = new DataOutputBuffer();
    final boolean processHeaders = (headers == null);

    try {
        ByteStreams.readBytes(new InputSupplier<InputStream>() {

            @Override
            public InputStream getInput() throws IOException {
                return System.in;
            }
        }, new ByteProcessor<Long>() {

            @Override
            public Long getResult() {
                return 0L;
            }

            int currLineCharCount = 0;
            boolean processingHeaders = processHeaders;

            @Override
            public boolean processBytes(byte[] buf, int start, int length) throws IOException {

                if (processingHeaders) {
                    int current = start;
                    int end = current + length;
                    while (processingHeaders && current != end) {
                        if (buf[current] != '\r' && buf[current] != '\n') {
                            currLineCharCount++;
                        } else if (buf[current] == '\n') {
                            if (currLineCharCount == 0) {
                                headerBuffer.write(buf, start, current - start + 1);
                                processingHeaders = false;
                            }
                            currLineCharCount = 0;
                        }
                        current++;
                    }
                    if (processingHeaders) {
                        headerBuffer.write(buf, start, length);
                    } else {
                        length -= current - start;
                        start = current;
                    }
                }
                if (!processingHeaders) {
                    contentBuffer.write(buf, start, length);
                }
                return true;
            }
        });

        LOG.info("CONTENT LEN:" + contentBuffer.getLength());
        //System.out.println(new String(contentBuffer.getData(),0,contentBuffer.getLength(),Charset.forName("UTF-8")));
        // decode header bytes ... 
        String header = "";
        if (headerBuffer.getLength() != 0) {
            try {
                header = new String(headerBuffer.getData(), 0, headerBuffer.getLength(),
                        Charset.forName("UTF-8"));
            } catch (Exception e) {
                LOG.warn(CCStringUtils.stringifyException(e));
                header = new String(headerBuffer.getData(), 0, headerBuffer.getLength(),
                        Charset.forName("ASCII"));
            }
        } else {
            if (headers != null) {
                header = headers.toString();
            }
        }
        LOG.info("HEADER LEN:" + header.length());
        System.out.println(header);

        //LOG.info("Parsing Document");
        ParseWorker worker = new ParseWorker();
        ParseResult result = new ParseResult();
        worker.parseDocument(result, 0L, 0L, baseURLObj, header,
                new FlexBuffer(contentBuffer.getData(), 0, contentBuffer.getLength()));
        LOG.info("Parse Result:" + result.getParseSuccessful());
        //LOG.info("Parse Data:" + result.toString());

        OutputStreamWriter outputWriter = new OutputStreamWriter(System.out, "UTF-8");
        JsonElement resultObj = parseResultToJSON(result);
        JsonWriter writer = new JsonWriter(outputWriter);
        writer.setIndent("    ");
        writer.setHtmlSafe(true);
        writer.setLenient(true);
        Streams.write(resultObj, writer);
        writer.flush();

        outputWriter.write("******** TEXT OUTPUT **********\n");
        outputWriter.write(result.getText());
        outputWriter.flush();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}