Example usage for java.io InputStreamReader InputStreamReader

List of usage examples for java.io InputStreamReader InputStreamReader

Introduction

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

Prototype

public InputStreamReader(InputStream in) 

Source Link

Document

Creates an InputStreamReader that uses the default charset.

Usage

From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java

public static void main(String[] args) {
    try {//from w  ww  .j av  a  2s . c o m
        final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        final String name = in.readLine();
        final List<RecordEntry> entries = new LinkedList<RecordEntry>();
        String line;
        while ((line = in.readLine()) != null) {
            final String[] parts = line.split("\\s+");
            final int length = Integer.parseInt(parts[0]);
            final int start = Integer.parseInt(parts[1]);
            final String entryName = parts[2];
            entries.add(new RecordEntry(length, start, entryName));
        }
        (new RecordClassMaker(name, entries)).execute();
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:GZIPcompress.java

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        System.out.println("Usage: \nGZIPcompress file\n" + "\tUses GZIP compression to compress "
                + "the file to test.gz");
        System.exit(1);//w  ww  .  ja va  2  s  . co m
    }
    BufferedReader in = new BufferedReader(new FileReader(args[0]));
    BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("test.gz")));
    System.out.println("Writing file");
    int c;
    while ((c = in.read()) != -1)
        out.write(c);
    in.close();
    out.close();
    System.out.println("Reading file");
    BufferedReader in2 = new BufferedReader(
            new InputStreamReader(new GZIPInputStream(new FileInputStream("test.gz"))));
    String s;
    while ((s = in2.readLine()) != null)
        System.out.println(s);
}

From source file:com.ccc.nhr.test1.NhrSocket.java

public static void main(String args[]) throws IOException, SQLException, ClassNotFoundException {

    final String host = "192.168.16.146";
    final int portNumber = 10010;

    System.out.println("Creating socket to '" + host + "' on port " + portNumber);
    Socket socket = new Socket(host, portNumber);

    final NhrDataService nhrConnection = new NhrConnectionBuilder(socket)
            .withInputBufferedReader(new BufferedReader(new InputStreamReader(socket.getInputStream())))
            .withDataInputStream(new DataInputStream(socket.getInputStream()))
            .withDataOutputStream(new DataOutputStream(socket.getOutputStream())).build();

    ReceiverThread receiverThread = new ReceiverThread();
    receiverThread.setNhrConnection(nhrConnection);
    receiverThread.start();/*w  ww.  ja v  a2 s.c  o m*/

    SenderThread senderThread = new SenderThread();
    senderThread.setNhrConnection(nhrConnection);
    senderThread.start();

}

From source file:eval.dataset.ParseWikiLog.java

public static void main(String[] ss) throws FileNotFoundException, ParserConfigurationException, IOException {
    FileInputStream fin = new FileInputStream("data/enwiki-20151201-pages-logging.xml.gz");
    GzipCompressorInputStream gzIn = new GzipCompressorInputStream(fin);
    InputStreamReader reader = new InputStreamReader(gzIn);
    BufferedReader br = new BufferedReader(reader);
    PrintWriter pw = new PrintWriter(new FileWriter("data/user_page.txt"));
    pw.println(/* w w  w. j  a  v  a 2  s .  co  m*/
            "#list of user names and pages that they have edited, deleted or created. These info are mined from logitems of enwiki-20150304-pages-logging.xml.gz");
    TreeMap<String, Set<String>> userPageList = new TreeMap();
    TreeSet<String> pageList = new TreeSet();
    int counterEntry = 0;
    String currentUser = null;
    String currentPage = null;
    try {
        for (String line = br.readLine(); line != null; line = br.readLine()) {

            if (line.trim().equals("</logitem>")) {
                counterEntry++;
                if (currentUser != null && currentPage != null) {
                    updateMap(userPageList, currentUser, currentPage);
                    pw.println(currentUser + "\t" + currentPage);
                    pageList.add(currentPage);
                }
                currentUser = null;
                currentPage = null;
            } else if (line.trim().startsWith("<username>")) {
                currentUser = line.trim().split(">")[1].split("<")[0].replace(" ", "_");

            } else if (line.trim().startsWith("<logtitle>")) {
                String content = line.trim().split(">")[1].split("<")[0];
                if (content.split(":").length == 1) {
                    currentPage = content.replace(" ", "_");
                }
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(ParseWikiLog.class.getName()).log(Level.SEVERE, null, ex);
    }
    pw.println("#analysed " + counterEntry + " entries of wikipesia log file");
    pw.println("#gathered a list of unique user of size " + userPageList.size());
    pw.println("#gathered a list of pages of size " + pageList.size());
    pw.close();
    gzIn.close();

    PrintWriter pwUser = new PrintWriter(new FileWriter("data/user_list_page_edited.txt"));
    pwUser.println(
            "#list of unique users and pages that they have edited, extracted from logitems of enwiki-20150304-pages-logging.xml.gz");
    for (String user : userPageList.keySet()) {
        pwUser.print(user);
        Set<String> getList = userPageList.get(user);
        for (String page : getList) {
            pwUser.print("\t" + page);
        }
        pwUser.println();
    }
    pwUser.close();

    PrintWriter pwPage = new PrintWriter(new FileWriter("data/all_pages.txt"));
    pwPage.println("#list of the unique pages that are extracted from enwiki-20150304-pages-logging.xml.gz");
    for (String page : pageList) {
        pwPage.println(page);
    }
    pwPage.close();
    System.out.println("#analysed " + counterEntry + " entries of wikipesia log file");
    System.out.println("#gathered a list of unique user of size " + userPageList.size());
    System.out.println("#gathered a list of pages of size " + pageList.size());
}

From source file:dataminning2.DataMinning2.java

/**
 * @param args the command line arguments
 *//*from w  w w  .  j  av  a 2  s  .co  m*/
public static void main(String[] args) throws IOException {
    // here is the code to load the iris.csv data in an array 

    int ColumnCount = 0;
    int RowCount = 0;
    double[][] Dataarraytest;
    double[][] Dataarray;
    double[][] SVDS = null;
    double[][] SVDU = null;
    double[][] SVDV = null;
    System.out.println("Do you want to work with 1.att.csv or 2.iris.csv  ");
    InputStreamReader Datasetchoice = new InputStreamReader(System.in);
    BufferedReader BDatasetChoice = new BufferedReader(Datasetchoice);
    int Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
    String path = null;
    // LOadData LDobj=new LOadData();
    LOadData LDobj = new LOadData();
    TrainingSetDecomposition TestDataonj = new TrainingSetDecomposition();
    SVDDecomposition SVDobj = new SVDDecomposition();

    switch (Datasetchoicevalue) {
    case 1:
        path = "Datasets\\att.csv";
        ColumnCount = LDobj.ColumnCount(path);
        RowCount = LDobj.RowCount(path);
        Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount);
        Dataarraytest = TestDataonj.Decomposition(RowCount, RowCount, 2, Dataarray);

        SVDS = SVDobj.DecompositionS(Dataarraytest);
        SVDU = SVDobj.DecompositionU(Dataarraytest);
        SVDV = SVDobj.DecompositionV(Dataarraytest);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "SVD");
        }

        KMeans_Ex4a Kmeanobj1 = new KMeans_Ex4a();
        double[][] KmeanData1 = Kmeanobj1.Main(SVDU);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSVKmean wcsvobj = new WriteCSVKmean();
            wcsvobj.writeCSVmethod(KmeanData1, "KMean");
        }

        Gui DBScanobj1 = new Gui();
        DBScanobj1.main(SVDU);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {

            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "DBScan");
        }

        break;

    case 2:
        path = "Datasets\\iris.csv";
        ColumnCount = LDobj.ColumnCount(path);
        RowCount = LDobj.RowCount(path);
        Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount);
        Dataarraytest = TestDataonj.Decomposition(RowCount, 150, ColumnCount, Dataarray);

        SVDS = SVDobj.DecompositionS(Dataarraytest);
        SVDU = SVDobj.DecompositionU(Dataarraytest);
        SVDV = SVDobj.DecompositionV(Dataarraytest);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "SVD");
        }

        KMeans_Ex4a Kmeanobj = new KMeans_Ex4a();
        double[][] KmeanData = Kmeanobj.Main(SVDU);
        ssecalc distobj = new ssecalc();
        String output = distobj.calc(KmeanData);
        System.out.println(output);
        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {
            WriteCSVKmean wcsvobj = new WriteCSVKmean();
            wcsvobj.writeCSVmethod(KmeanData, "KMean");
        }

        Gui DBScanobj = new Gui();
        DBScanobj.main(SVDU);

        System.out.println("Do you want the graph to be plotted 1.yes 2.No");
        Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine());
        if (Datasetchoicevalue == 1) {

            WriteCSv wcsvobj = new WriteCSv();
            wcsvobj.writeCSVmethod(SVDU, "DBScan");
        }

        break;
    }

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");

    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    SSLSession session = ((SSLSocket) s).getSession();
    Certificate[] cchain = session.getPeerCertificates();
    System.out.println("The Certificates used by peer");
    for (int i = 0; i < cchain.length; i++) {
        System.out.println(((X509Certificate) cchain[i]).getSubjectDN());
    }//  www .jav  a2  s .c o m
    System.out.println("Peer host is " + session.getPeerHost());
    System.out.println("Cipher is " + session.getCipherSuite());
    System.out.println("Protocol is " + session.getProtocol());
    System.out.println("ID is " + new BigInteger(session.getId()));
    System.out.println("Session created in " + session.getCreationTime());
    System.out.println("Session accessed in " + session.getLastAccessedTime());

    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String x = in.readLine();
    System.out.println(x);
    in.close();

}

From source file:com.manning.blogapps.chapter10.examples.AuthGetJava.java

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.out.println("USAGE: authget <username> <password> <url>");
        System.exit(-1);//from w ww.  j  av  a2  s .c  o m
    }
    String credentials = args[0] + ":" + args[1];

    URL url = new URL(args[2]);
    URLConnection conn = url.openConnection();

    conn.setRequestProperty("Authorization",
            "Basic " + new String(Base64.encodeBase64(credentials.getBytes())));

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    String s = null;
    while ((s = in.readLine()) != null) {
        System.out.println(s);
    }
}

From source file:edu.harvard.med.iccbl.dev.HibernateConsole.java

public static void main(String[] args) {
    BufferedReader br = null;//from w ww.j  a  va 2  s . c o  m
    try {
        CommandLineApplication app = new CommandLineApplication(args);
        app.processOptions(true, false);
        br = new BufferedReader(new InputStreamReader(System.in));

        EntityManagerFactory emf = (EntityManagerFactory) app.getSpringBean("entityManagerFactory");
        EntityManager em = emf.createEntityManager();

        do {
            System.out.println("Enter HQL query (blank to quit): ");
            String input = br.readLine();
            if (input.length() == 0) {
                System.out.println("Goodbye!");
                System.exit(0);
            }
            try {
                List list = ((Session) em.getDelegate()).createQuery(input).list(); // note: this uses the Hibernate Session object, to allow HQL (and JPQL)
                // List list = em.createQuery(input).getResultList();  // note: this JPA method supports JPQL

                System.out.println("Result:");
                for (Iterator iter = list.iterator(); iter.hasNext();) {
                    Object item = iter.next();
                    // format output from multi-item selects ("select a, b, c, ... from ...")
                    if (item instanceof Object[]) {
                        List<Object> fields = Arrays.asList((Object[]) item);
                        System.out.println(StringUtils.makeListString(fields, ", "));
                    }
                    // format output from single-item selected ("select a from ..." or "from ...")
                    else {
                        System.out.println("[" + item.getClass().getName() + "]: " + item);
                    }
                }
                System.out.println("(" + list.size() + " rows)\n");
            } catch (Exception e) {
                System.out.println("Hibernate Error: " + e.getMessage());
                log.error("Hibernate error", e);
            }
            System.out.println();
        } while (true);
    } catch (Exception e) {
        System.err.println("Fatal Error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(br);
    }
}

From source file:StringTaggerDemo.java

public static void main(String args[]) {
    try {//  w  ww. j a v  a 2 s  . com
        System.setProperty("sen.home", "../Sen1221/senhome-ipadic");
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "FATAL");

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please input Japanese sentence:");

        StringTagger tagger = StringTagger.getInstance();
        // You can also get StringTagger instance by following code:
        //
        // String confPath = System.getProperty("sen.home")
        // + System.getProperty("file.separator") + "conf/sen.xml";
        // tagger = StringTagger.getInstance(confPath);

        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
            Token[] token = tagger.analyze(s);
            if (token != null) {
                for (int i = 0; i < token.length; i++) {
                    System.out.println(token[i].toString() + "\t(" + token[i].getBasicString() + ")" + "\t"
                            + token[i].getPos() + "(" + token[i].start() + "," + token[i].end() + ","
                            + token[i].length() + ")\t" + token[i].getReading() + "\t"
                            + token[i].getPronunciation());
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ExecDemoLs.java

public static void main(String argv[]) throws IOException {

    final Process p; // Process tracks one external native process
    BufferedReader is; // reader for output of process
    String line;/*from   w  ww  .  j  a v  a  2s. co m*/

    p = Runtime.getRuntime().exec(PROGRAM);

    // Optional: start a thread to wait for the process to terminate.
    // Don't just wait in main line, but here set a "done" flag and
    // use that to control the main reading loop below.
    Thread waiter = new Thread() {
        public void run() {
            try {
                p.waitFor();
            } catch (InterruptedException ex) {
                // OK, just quit.
                return;
            }
            System.out.println("Program terminated!");
            done = true;
        }
    };
    waiter.start();

    // getInputStream gives an Input stream connected to
    // the process p's standard output (and vice versa). We use
    // that to construct a BufferedReader so we can readLine() it.
    is = new BufferedReader(new InputStreamReader(p.getInputStream()));

    while (!done && ((line = is.readLine()) != null))
        System.out.println(line);

    return;
}