Example usage for java.io OutputStreamWriter close

List of usage examples for java.io OutputStreamWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    try {//from w  w  w .j a v a2  s. c  o m
        char[] chars = new char[2];
        chars[0] = '\u4F60';
        chars[1] = '\u597D';
        String encoding = "GB18030";
        File textFile = new File("C:\\temp\\myFile.txt");
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(textFile), encoding);
        writer.write(chars);
        writer.close();
    } catch (IOException e) {
        System.out.println(e.toString());
    }
}

From source file:ChannelToWriter.java

public static void main(String[] args) throws IOException {
    FileChannel c = new FileInputStream(args[0]).getChannel();
    OutputStreamWriter w = new OutputStreamWriter(System.out);
    Charset utf8 = Charset.forName("UTF-8");
    ChannelToWriter.copy(c, w, utf8);/* w  ww. j  a  v a  2  s .  c  o  m*/
    c.close();
    w.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(false);//from  w  w  w .j  a v  a2  s  .  c om
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new FileInputStream(new File("input.xml")));
    File OutputDOM = new File("out.txt");
    FileOutputStream fostream = new FileOutputStream(OutputDOM);
    OutputStreamWriter oswriter = new OutputStreamWriter(fostream);
    BufferedWriter bwriter = new BufferedWriter(oswriter);
    if (!OutputDOM.exists()) {
        OutputDOM.createNewFile();
    }
    visitRecursively(doc, bwriter);
    bwriter.close();
    oswriter.close();
    fostream.close();
}

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

public static void main(String[] argv) {
    try {//from  w w  w .  jav  a2  s  .  co  m
        Namespace args = parseArgs(argv);

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

        log.trace("Finding files to analyse...");
        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 scope = Analyser.analyse(files, args.getAttrs());

        if (args.get(OUTPUT_LOCATION) != null) {
            IO.putAPIData(scope, args.getString(Args.OUTPUT_FORMAT_OPTION),
                    args.getString(Analyser.ENCODING_OPTION), args.getString(OUTPUT_LOCATION),
                    args.getString(Args.USERNAME_OPTION), args.getString(Args.PASSWORD_OPTION));
        } else {
            OutputStreamWriter writer = new OutputStreamWriter(System.out);
            Serializers.dumpAPIScope(scope, 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:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {//w ww .j a va 2s . com

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

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

public static void main(String[] argv) {
    try {// w ww.  ja  v  a 2 s .c  o 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:Main.java

public static void main(String[] argv) throws Exception {
    String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
    data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");

    URL url = new URL("http://server.com:80/cgi");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);/*from  ww  w  .java  2s  . c o m*/
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();

    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }
    wr.close();
    rd.close();
}

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

public static void main(String[] argv) {
    try {//w  w  w  . ja  v a 2 s. 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) {

    String s = "from java2s.com!";

    try {//  w w w.ja va  2  s  .  c  o  m

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

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com!";

    try {//from ww  w  .j a v a  2 s.  com

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder());

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}