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.github.brandtg.stl.StlPlotter.java

public static void main(String[] args) throws Exception {
    List<Double> times = new ArrayList<Double>();
    List<Double> series = new ArrayList<Double>();
    List<Double> trend = new ArrayList<Double>();
    List<Double> seasonal = new ArrayList<Double>();
    List<Double> remainder = new ArrayList<Double>();

    // Read from STDIN
    String line;/*from  w  w  w.  j a  v  a 2  s  . co  m*/
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(",");
        times.add(Double.valueOf(tokens[0]));
        series.add(Double.valueOf(tokens[1]));
        trend.add(Double.valueOf(tokens[2]));
        seasonal.add(Double.valueOf(tokens[3]));
        remainder.add(Double.valueOf(tokens[4]));
    }

    StlResult res = new StlResult(convert(times), convert(series), convert(trend), convert(seasonal),
            convert(remainder));

    if (args.length == 1) {
        plot(res, new File(args[0]));
    } else {
        plotOnScreen(res, "Seasonal Decomposition");
    }
}

From source file:fr.ippon.tatami.test.support.LdapTestServer.java

/**
 * Main class. We just do a lookup on the server to check that it's available.
 * //  ww  w .j  a va 2s  . c  o m
 * @param args
 *            Not used.
 * @throws Exception
 */
public static void main(String[] args) throws Exception // throws Exception
{
    FileUtils.deleteDirectory(workingDir);

    LdapTestServer ads = null;
    try {
        // Create the server
        ads = new LdapTestServer();
        ads.start();

        // Read an entry
        Entry result = ads.service.getAdminSession().lookup(new LdapDN("dc=ippon,dc=fr"));

        // And print it if available
        System.out.println("Found entry : " + result);

    } catch (Exception e) {
        // Ok, we have something wrong going on ...
        e.printStackTrace();
    }
    System.out.println("Press enter");
    new BufferedReader(new InputStreamReader(System.in)).readLine();
    ads.stop();
}

From source file:com.github.ruananswer.stl.StlPlotter.java

public static void main(String[] args) throws Exception {
    List<Double> times = new ArrayList<Double>();
    List<Double> series = new ArrayList<Double>();
    List<Double> trend = new ArrayList<Double>();
    List<Double> seasonal = new ArrayList<Double>();
    List<Double> remainder = new ArrayList<Double>();

    // Read from STDIN
    String line;/*  w  w  w .  j  a  v  a2 s . c o m*/
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.split(",");
        times.add(Double.valueOf(tokens[0]));
        series.add(Double.valueOf(tokens[1]));
        trend.add(Double.valueOf(tokens[2]));
        seasonal.add(Double.valueOf(tokens[3]));
        remainder.add(Double.valueOf(tokens[4]));
    }

    STLResult res = new STLResult(convert(trend), convert(seasonal), convert(remainder));

    double[] tmpSeries = convert(series);
    double[] tmpTimes = convert(times);

    if (args.length == 1) {
        plot(res, tmpSeries, tmpTimes, new File(args[0]));
    } else {
        plotOnScreen(res, tmpSeries, tmpTimes, "Seasonal Decomposition");
    }
}

From source file:PeerDiscovery.java

/**
 * @param args/*w  w  w. j  a  v a2 s .co  m*/
 */
public static void main(String[] args) {
    try {
        int group = 6969;

        PeerDiscovery mp = new PeerDiscovery(group, 6969);

        boolean stop = false;

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while (!stop) {
            System.out.println("enter \"q\" to quit, or anything else to query peers");
            String s = br.readLine();

            if (s.equals("q")) {
                System.out.print("Closing down...");
                mp.disconnect();
                System.out.println(" done");
                stop = true;
            } else {
                System.out.println("Querying");

                Peer[] peers = mp.getPeers(100, (byte) 0);

                System.out.println(peers.length + " peers found");
                for (Peer p : peers) {
                    System.out.println("\t" + p);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.genentech.chemistry.openEye.apps.enumerate.SDFEnumerator.java

public static void main(String... args) throws IOException {
    Options options = new Options();
    Option opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(true);//  w  w w  .  j a va 2 s .  c  o m
    options.addOption(opt);

    opt = new Option("hydrogenExplicit", false, "Use explicit hydrogens");
    options.addOption(opt);

    opt = new Option("correctValences", false, "Correct valences after the enumeration");
    options.addOption(opt);

    opt = new Option("regenerate2D", false, "Regenerate 2D coordinates for the products");
    options.addOption(opt);

    opt = new Option("reactAllSites", false, "Generate a product for each match in a reagent.");
    options.addOption(opt);

    opt = new Option("randomFraction", true, "Only output a fraction of the products.");
    options.addOption(opt);

    opt = new Option("maxAtoms", true, "Only output products with <= maxAtoms.");
    options.addOption(opt);

    opt = new Option("notReacted", true,
            "Output file for reagents that didn't produce at leaste one output molecule, useful for debugging SMIRKS.");
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp("", options);
    }

    args = cmd.getArgs();
    if (args.length < 2) {
        exitWithHelp("Transformation and/or reagentFiles missing", options);
    }
    String smirks = args[0];
    if (new File(smirks).canRead())
        smirks = IOUtil.fileToString(smirks).trim();
    if (!smirks.contains(">>"))
        smirks = scaffoldToSmirks(smirks);
    String[] reagentSmiOrFiles = Arrays.copyOfRange(args, 1, args.length);

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String outFile = cmd.getOptionValue("out");
    OELibraryGen lg = new OELibraryGen();
    lg.Init(smirks);
    if (!lg.IsValid())
        exitWithHelp("Invalid Transform: " + smirks, options);

    lg.SetExplicitHydrogens(cmd.hasOption("hydrogenExplicit"));
    lg.SetValenceCorrection(cmd.hasOption("correctValences"));
    lg.SetRemoveUnmappedFragments(true);

    boolean regenerate2D = cmd.hasOption("regenerate2D");
    boolean reactAllSites = cmd.hasOption("reactAllSites");
    String unreactedFile = null;
    if (cmd.hasOption("notReacted")) {
        unreactedFile = cmd.getOptionValue("notReacted");
    }

    double randomFract = 2;
    if (cmd.hasOption("randomFraction"))
        randomFract = Double.parseDouble(cmd.getOptionValue("randomFraction"));

    int maxAtoms = 0;
    if (cmd.hasOption("maxAtoms"))
        maxAtoms = Integer.parseInt(cmd.getOptionValue("maxAtoms"));

    SDFEnumerator en = new SDFEnumerator(lg, reactAllSites, reagentSmiOrFiles);
    en.generateLibrary(outFile, maxAtoms, randomFract, regenerate2D, unreactedFile);
    en.delete();
}

From source file:edu.oregonstate.eecs.mcplan.domains.inventory.InventorySimulator.java

public static void main(final String[] argv) throws IOException {
    final RandomGenerator rng = new MersenneTwister(42);
    final int Nproducts = 2;
    final int max_inventory = 10;
    final double warehouse_cost = 1;
    final int min_order = 1;
    final int max_order = 2;
    final double delivery_probability = 0.5;
    final int max_demand = 5;
    final int[] price = new int[] { 1, 2 };

    final InventoryProblem problem = InventoryProblem.TwoProducts();
    //         Nproducts, price, max_inventory, warehouse_cost, min_order, max_order, delivery_probability, max_demand );

    while (true) {

        final InventoryState s = new InventoryState(rng, problem);
        final InventorySimulator sim = new InventorySimulator(s);

        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (!s.isTerminal()) {
            System.out.println(sim.state());

            final String cmd = reader.readLine();
            final String[] tokens = cmd.split(",");

            final InventoryAction a;
            if ("n".equals(tokens[0])) {
                a = new InventoryNothingAction();
            } else {
                final int product = Integer.parseInt(tokens[0]);
                final int quantity = Integer.parseInt(tokens[1]);
                a = new InventoryOrderAction(product, quantity, s.problem.cost[product]);
            }//from  w w  w  .  j a  v a 2s.  co  m

            sim.takeAction(new JointAction<InventoryAction>(a));

            System.out.println("r = " + Arrays.toString(sim.reward()));
        }

        //         System.out.print( "Hand: " );
        //         System.out.print( sim.state().player_hand );
        //         System.out.print( " (" );
        //         final ArrayList<int[]> values = sim.state().player_hand.values();
        //         for( int i = 0; i < values.size(); ++i ) {
        //            if( i > 0 ) {
        //               System.out.print( ", " );
        //            }
        //            System.out.print( Arrays.toString( values.get( i ) ) );
        //         }
        //         System.out.println( ")" );
        //
        //         System.out.print( "Reward: " );
        //         System.out.println( Arrays.toString( sim.reward() ) );
        //         System.out.print( "Dealer hand: " );
        //         System.out.print( sim.state().dealerHand().toString() );
        //         System.out.print( " (" );
        //         System.out.print( SpBjHand.handValue( sim.state().dealerHand() )[0] );
        //         System.out.println( ")" );
        //         System.out.println( "----------------------------------------" );
    }
}

From source file:calendarevent.CalendarEvent.java

/**
 * @param args the command line arguments
 *///from  w w  w . ja  v a 2  s. c  o  m
public static void main(String[] args) {
    // TODO code application logic here

    /*       
                
        This has to be replaced with the json data coming from the getJsonData() method
        Expecting the Json will be in the format from the above methid.
                
    */
    String jsonString = "{\n" + " \"kind\": \"calendar#events\",\n"
            + " \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/QElT1PHkP9d3G5VSndpdEMlSzKE\\\"\",\n"
            + " \"summary\": \"PushEvents\",\n" + " \"description\": \"Hackathon\",\n"
            + " \"updated\": \"2014-03-29T22:35:18.495Z\",\n" + " \"timeZone\": \"Asia/Calcutta\",\n"
            + " \"accessRole\": \"reader\",\n" + " \"items\": [\n" + "  {\n"
            + "   \"kind\": \"calendar#event\",\n"
            + "   \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/MTM5NjEyNTQwNzcxMTAwMA\\\"\",\n"
            + "   \"id\": \"q28lprjb8ad3m17955lf1p9d48\",\n" + "   \"status\": \"confirmed\",\n"
            + "   \"htmlLink\": \"https://www.google.com/calendar/event?eid=cTI4bHByamI4YWQzbTE3OTU1bGYxcDlkNDggM3RvcjdvamZxaWhlamNqNjduOWw0dDhnMmNAZw\",\n"
            + "   \"created\": \"2014-03-29T20:36:47.000Z\",\n"
            + "   \"updated\": \"2014-03-29T20:36:47.711Z\",\n" + "   \"summary\": \"Test API\",\n"
            + "   \"creator\": {\n" + "    \"email\": \"vrohitrao@gmail.com\",\n"
            + "    \"displayName\": \"Rohith Vallu\"\n" + "   },\n" + "   \"organizer\": {\n"
            + "    \"email\": \"3tor7ojfqihejcj67n9l4t8g2c@group.calendar.google.com\",\n"
            + "    \"displayName\": \"PushEvents\",\n" + "    \"self\": true\n" + "   },\n"
            + "   \"start\": {\n" + "    \"dateTime\": \"2014-03-30T02:30:00+05:30\"\n" + "   },\n"
            + "   \"end\": {\n" + "    \"dateTime\": \"2014-03-30T03:30:00+05:30\"\n" + "   },\n"
            + "   \"iCalUID\": \"q28lprjb8ad3m17955lf1p9d48@google.com\",\n" + "   \"sequence\": 0\n" + "  },\n"
            + "  {\n" + "   \"kind\": \"calendar#event\",\n"
            + "   \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/MTM5NjEzMjUzMjQxNzAwMA\\\"\",\n"
            + "   \"id\": \"jgpue3stuo3js5qlsodob84voo\",\n" + "   \"status\": \"confirmed\",\n"
            + "   \"htmlLink\": \"https://www.google.com/calendar/event?eid=amdwdWUzc3R1bzNqczVxbHNvZG9iODR2b28gM3RvcjdvamZxaWhlamNqNjduOWw0dDhnMmNAZw\",\n"
            + "   \"created\": \"2014-03-29T22:35:32.000Z\",\n"
            + "   \"updated\": \"2014-03-29T22:35:32.417Z\",\n" + "   \"summary\": \"Test Events\",\n"
            + "   \"description\": \"Hack!!\",\n"
            + "   \"location\": \"Northeastern University, Huntington Avenue, Boston, MA, United States\",\n"
            + "   \"creator\": {\n" + "    \"email\": \"vrohitrao@gmail.com\",\n"
            + "    \"displayName\": \"Rohith Vallu\"\n" + "   },\n" + "   \"organizer\": {\n"
            + "    \"email\": \"3tor7ojfqihejcj67n9l4t8g2c@group.calendar.google.com\",\n"
            + "    \"displayName\": \"PushEvents\",\n" + "    \"self\": true\n" + "   },\n"
            + "   \"start\": {\n" + "    \"dateTime\": \"2014-03-30T04:30:00+05:30\"\n" + "   },\n"
            + "   \"end\": {\n" + "    \"dateTime\": \"2014-03-30T19:30:00+05:30\"\n" + "   },\n"
            + "   \"visibility\": \"public\",\n"
            + "   \"iCalUID\": \"jgpue3stuo3js5qlsodob84voo@google.com\",\n" + "   \"sequence\": 0\n" + "  }\n"
            + " ]\n" + "}";

    Gson gson = new Gson();
    try {
        JSONObject jsonData = new JSONObject(jsonString);
        JSONArray jsonArray = jsonData.getJSONArray("items");
        JSONObject eventData;
        Event event = new Event();
        for (int i = 0; i < jsonArray.length(); i++) {

            System.out.println(jsonArray.get(i).toString());
            Items item = gson.fromJson(jsonArray.get(i).toString(), Items.class);

            event.setSummary(item.getSummary());
            event.setLocation(item.getLocation());

            /* Will be adding the attendees here
             ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>();
             attendees.add(new EventAttendee().setEmail("attendeeEmail"));
             // ...
             event.setAttendees(attendees);
             */
            Date startDate = new Date();
            Date endDate = new Date(startDate.getTime() + 3600000);
            DateTime start = new DateTime(startDate, TimeZone.getDefault().getDefault().getTimeZone("UTC"));
            event.setStart(new EventDateTime().setDateTime(start));
            DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
            event.setEnd(new EventDateTime().setDateTime(end));
            HttpTransport transport = new NetHttpTransport();
            JsonFactory jsonFactory = new JacksonFactory();
            Calendar.Builder builder = new Calendar.Builder(transport, jsonFactory, null);
            String clientID = "937140966210.apps.googleusercontent.com";
            String redirectURL = "urn:ietf:wg:oauth:2.0:oob";
            String clientSecret = "qMFSb_cadYDG7uh3IDXWiMQY";
            ArrayList<String> scope = new ArrayList<String>();
            scope.add("https://www.googleapis.com/auth/calendar");

            String url = new GoogleAuthorizationCodeRequestUrl(clientID, redirectURL, scope).build();

            System.out.println("Go to the following link in your browser:");
            System.out.println(url);

            // Read the authorization code from the standard input stream.
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("What is the authorization code?");
            String code = in.readLine();

            GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory,
                    clientID, clientSecret, redirectURL, code, redirectURL).execute();

            GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);

            Calendar service = new Calendar.Builder(transport, jsonFactory, credential).build();

            Event createdEvent = service.events().insert(item.getSummary(), event).execute();

            System.out.println(createdEvent.getId());

        }

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

From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java

/**
 * @param args/*from  w  w  w.  j  a v  a 2 s  . co m*/
 */
public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option(OPT_INFILE, true,
            "input file oe-supported Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    opt.setArgName("fn");
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    opt.setArgName("fn");
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    if (args.length == 0) {
        System.err.println("Specify at least one index type");
        exitWithHelp(options);
    }

    String inFile = cmd.getOptionValue(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);
    Set<String> selectedIndexes = new HashSet<String>(args.length);
    if (args.length == 1 && "all".equalsIgnoreCase(args[0]))
        selectedIndexes = AVAILIndexes;
    else
        selectedIndexes.addAll(Arrays.asList(args));

    if (!AVAILIndexes.containsAll(selectedIndexes)) {
        selectedIndexes.removeAll(AVAILIndexes);
        StringBuilder err = new StringBuilder("Unknown Index types: ");
        for (String it : selectedIndexes)
            err.append(it).append(" ");
        System.err.println(err);
        exitWithHelp(options);
    }

    SDFTopologicalIndexer sdfIndexer = new SDFTopologicalIndexer(outFile, selectedIndexes);

    sdfIndexer.run(inFile);
    sdfIndexer.close();
}

From source file:fr.ippon.pamelaChu.test.support.LdapTestServer.java

/**
 * Main class. We just do a lookup on the server to check that it's available.
 * <p/>/*from ww  w . ja v a2s. c o m*/
 * FIXME : in Eclipse : when running this classes as "Java Application", target/test-classes is not added in the classpath
 * resulting in a java.lang.ClassNotFoundException ...
 *
 * @param args Not used.
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    FileUtils.deleteDirectory(workingDir);

    LdapTestServer ads = null;
    try {
        // Create the server
        ads = new LdapTestServer();
        ads.start();

        // Read an entry
        Entry result = ads.service.getAdminSession().lookup(new LdapDN("dc=ippon,dc=fr"));

        // And print it if available
        System.out.println("Found entry : " + result);

    } catch (Exception e) {
        // Ok, we have something wrong going on ...
        e.printStackTrace();
    }
    System.out.println("Press enter");
    new BufferedReader(new InputStreamReader(System.in)).readLine();
    ads.stop();
}

From source file:org.dlut.mycloudserver.service.performancemonitor.PerformanceListener.java

public static void main(String[] args) {
    long t1 = System.currentTimeMillis();

    String url = "http://127.0.0.1:8001";
    URLConnection conn;//from   w ww . jav a 2  s .  c  o  m
    try {
        conn = new URL(url).openConnection();
        conn.setConnectTimeout(1000);
        conn.setReadTimeout(1000);
        InputStream is = conn.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String res = br.readLine();
        br.close();
        is.close();
        JSONObject jsonRes = JSON.parseObject(res);
        double loadAverage = jsonRes.getDoubleValue("loadAverage");
        System.out.println(loadAverage);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    long t2 = System.currentTimeMillis();

    System.out.println((t2 - t1) + "ms");
}