Example usage for java.io Reader close

List of usage examples for java.io Reader close

Introduction

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

Prototype

public abstract void close() throws IOException;

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    // create a char array to read chars into
    char cbuf[] = new char[5];

    try {//from w  w w  . ja  v  a  2 s .c om
        // read characters into an array.
        System.out.println(reader.read(cbuf));

        System.out.println(cbuf);
        reader.close();

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

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    // create a new StringReader
    Reader reader = new StringReader(s);

    try {/*from   www  .j a v a2  s.co m*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }
        System.out.println(reader.markSupported());
        reader.close();

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

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    // create a char array to read chars into
    char cbuf[] = new char[5];

    try {//from w  w w. ja va  2s.c  o  m
        // read characters into a portion of an array.
        System.out.println(reader.read(cbuf, 0, 5));

        System.out.println(cbuf);

        reader.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    try {/*from   www.  jav  a 2  s  . c  o m*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();

            // skip a char every time
            reader.skip(1);

            System.out.println(c);
        }
        reader.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.peer2gear.nutch.xquery.XQueryParseFilter.java

public static void main(String[] args) throws Exception {
    Configuration conf = NutchConfiguration.create();
    Content content = null;/*from w  w w  .java  2 s  .c o  m*/
    if (args.length < 1) {
        usage();
        return;
    }
    String urlStr = args[0];
    String segment = null;
    if (args.length == 2) {
        segment = args[1];
    }
    if (segment != null) {
        Path file = new Path(segment, Content.DIR_NAME);
        FileSystem fs = FileSystem.get(conf);
        System.out.println("path: " + file.toString());
        Reader[] readers = MapFileOutputFormat.getReaders(fs, file, conf);
        content = new Content();
        for (Reader reader : readers) {
            if (reader.get(new Text(urlStr), content) != null)
                continue;
        }
        for (Reader reader : readers)
            reader.close();
    } else {
        content = createContent(conf, urlStr);
    }
    Parse parse = new ParseUtil(conf).parse(content).get(content.getUrl());
    String result = parse.getData().getMeta(XQueryParseFilter.METADATA_FIELD);
    System.out.println(result);
}

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    try {// ww w. j  a  v a  2 s  . co m
        // check if reader is ready
        System.out.println(reader.ready());

        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }
        reader.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:edu.uci.ics.asterix.drivers.AsterixCLI.java

public static void main(String args[]) throws Exception {
    Options options = new Options();
    CmdLineParser parser = new CmdLineParser(options);
    parser.parseArgument(args);//from  w w w  .  j ava  2 s. c o m

    setUp(options);
    try {
        for (String queryFile : options.args) {
            Reader in = new FileReader(queryFile);
            AsterixJavaClient ajc = new AsterixJavaClient(
                    AsterixHyracksIntegrationUtil.getHyracksClientConnection(), in);
            try {
                ajc.compile(true, false, false, false, false, true, false);
            } finally {
                in.close();
            }
            ajc.execute();
        }
    } finally {
        tearDown();
    }
    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) {
    try {//from  w  w w. j a v a 2  s. c  o m
        String s = "tutorial from java2s.com";

        Reader reader = new StringReader(s);

        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }

        reader.mark(10);

        for (int i = 0; i < 6; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }

        reader.reset();

        for (int i = 0; i < 6; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }
        reader.close();

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

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    try {// www .java2 s.  c  o m
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.print(c);
        }

        reader.mark(10);

        for (int i = 0; i < 6; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }

        reader.reset();

        for (int i = 0; i < 6; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }

        reader.close();

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

From source file:se.vgregion.portal.cs.util.CryptoUtilImpl.java

/**
 * Main method used for creating initial key file.
 * //from  w  ww. j a v a2  s.c om
 * @param args
 *            - not used
 */
public static void main(String[] args) {
    final String keyFile = "./howto.key";
    final String pwdFile = "./howto.properties";

    CryptoUtilImpl cryptoUtils = new CryptoUtilImpl();
    cryptoUtils.setKeyFile(new File(keyFile));

    String clearPwd = "my_cleartext_pwd";

    Properties p1 = new Properties();
    Writer w = null;
    try {
        p1.put("user", "liferay");
        String encryptedPwd = cryptoUtils.encrypt(clearPwd);
        p1.put("pwd", encryptedPwd);
        w = new FileWriter(pwdFile);
        p1.store(w, "");
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (w != null) {
            try {
                w.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    // ==================
    Properties p2 = new Properties();
    Reader r = null;
    try {
        r = new FileReader(pwdFile);
        p2.load(r);
        String encryptedPwd = p2.getProperty("pwd");
        System.out.println(encryptedPwd);
        System.out.println(cryptoUtils.decrypt(encryptedPwd));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (GeneralSecurityException e) {
        e.printStackTrace();
    } finally {
        if (r != null) {
            try {
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}