List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:GrowBufferedReader.java
public static void main(String... args) { try {/*from w ww . ja v a 2 s . c om*/ BufferedReader br = new BufferedReader(car); Class<?> c = br.getClass(); Field f = c.getDeclaredField("cb"); // cb is a private field f.setAccessible(true); char[] cbVal = char[].class.cast(f.get(br)); char[] newVal = Arrays.copyOf(cbVal, cbVal.length * 2); if (args.length > 0 && args[0].equals("grow")) f.set(br, newVal); for (int i = 0; i < srcBufSize; i++) br.read(); // see if the new backing array is being used if (newVal[srcBufSize - 1] == src[srcBufSize - 1]) out.format("Using new backing array, size=%d%n", newVal.length); else out.format("Using original backing array, size=%d%n", cbVal.length); // production code should handle these exceptions more gracefully } catch (FileNotFoundException x) { x.printStackTrace(); } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } catch (IOException x) { x.printStackTrace(); } }
From source file:no.uib.tools.OnthologyHttpClient.java
public static void main(String[] args) { try {/*www. j a v a 2 s.co m*/ CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet getRequest = new HttpGet( "http://www.ebi.ac.uk/ols/api/ontologies/mod/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMOD_00861/descendants?size=2002"); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed to get the PSIMOD onthology : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; FileWriter fw = new FileWriter("./mod.json"); System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); fw.write(output); } fw.close(); httpClient.close(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:TreeNode.java
public static void main(String[] argv) throws IOException { BinaryTree bt = new BinaryTree(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int val; char ch = ' '; String clearbuffer;/*from w ww.j a va 2 s. c o m*/ do { System.out.print("Enter a number: "); val = Integer.parseInt(br.readLine()); bt.insert(val); System.out.print("Do you wish to enter more values (Y/N)....."); ch = (char) br.read(); clearbuffer = br.readLine(); } while (ch == 'y' || ch == 'Y'); System.out.println("Postorder traversal of given tree is: "); bt.postorder(); System.out.println("Preorder traversal of given tree is: "); bt.preorder(); System.out.println("Inorder traversal of given tree is: "); bt.inorder(); }
From source file:com.navercorp.client.Main.java
public static void main(String[] args) { Client clnt = null;/*ww w .j ava 2s . c o m*/ try { CommandLine cmd = new DefaultParser() .parse(new Options().addOption("z", true, "zookeeper address (ip:port,ip:port,...)") .addOption("t", true, "zookeeper connection timeout") .addOption("c", true, "command and arguments"), args); final String connectionString = cmd.hasOption("z") ? cmd.getOptionValue("z") : "127.0.0.1:2181"; final int timeout = cmd.hasOption("t") ? Integer.valueOf(cmd.getOptionValue("t")) : 10000; clnt = new Client(connectionString, timeout); String command; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while ((command = in.readLine()) != null) { printResult(clnt.execute(command.split(" "))); } System.exit(Code.OK.n()); } catch (ParseException e) { e.printStackTrace(System.err); System.err.println(Client.getUsage()); System.exit(INVALID_ARGUMENT.n()); } catch (IOException e) { e.printStackTrace(System.err); System.exit(ZK_CONNECTION_LOSS.n()); } catch (InterruptedException e) { e.printStackTrace(System.err); System.exit(INTERNAL_ERROR.n()); } finally { if (clnt != null) { try { clnt.close(); } catch (Exception e) { ; // nothing to do } } } }
From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); int iCounter = 0; int fpCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);// w w w . ja va 2 s . c o m options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4"); opt.setRequired(true); options.addOption(opt); opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)"); opt.setRequired(false); 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) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = false; boolean hashUnknownFrag = false; Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("i"); oemolistream ifs = new oemolistream(inFile); double fract = 2D; String tmp = cmd.getOptionValue("sampleFract"); if (tmp != null) fract = Double.parseDouble(tmp); Random rnd = new Random(); LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper(); int dictSize = mapper.getMaxIdx() + 1; int[] freq = new int[dictSize]; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; if (rnd.nextDouble() < fract) { fpCounter++; Fingerprint fp = fprinter.getFingerprint(mol); for (int bit : fp.getBits()) freq[bit]++; } if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %d %dsec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); } } System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); mapper.reSortDictionary(freq); mapper.writeDictionary(); fprinter.close(); }
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/* www . j ava 2 s. c o m*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:SifterJava.java
public static void main(String[] args) throws Exception { /** Enter your sifter account and access key in the ** string fields below *///from www . j av a2s. c om // create URL object to SifterAPI String yourAccount = "your-account"; // enter your account name String yourDomain = yourAccount + ".sifterapp.com"; URL sifter = new URL("https", yourDomain, "/api/projects"); // open connectino to SifterAPI URLConnection sifterConnection = sifter.openConnection(); // add Access Key to header request String yourAccessKey = "your-32char-sifterapi-access-key"; // enter your access key sifterConnection.setRequestProperty("X-Sifter-Token", yourAccessKey); // add Accept: application/json to header - also not necessary sifterConnection.addRequestProperty("Accept", "application/json"); // URLconnection.connect() not necessary // getInputStream will connect // don't make a content handler, org.json reads a stream! // create buffer and open input stream BufferedReader in = new BufferedReader(new InputStreamReader(sifterConnection.getInputStream())); // don't readline, create stringbuilder, append, create string // construct json tokener from input stream or buffered reader JSONTokener x = new JSONTokener(in); // initialize "projects" JSONObject from string JSONObject projects = new JSONObject(x); // prettyprint "projects" System.out.println("************ projects ************"); System.out.println(projects.toString(2)); // array of projects JSONArray array = projects.getJSONArray("projects"); int arrayLength = array.length(); JSONObject[] p = new JSONObject[arrayLength]; // projects for (int i = 0; i < arrayLength; i++) { p[i] = array.getJSONObject(i); System.out.println("************ project: " + (i + 1) + " ************"); System.out.println(p[i].toString(2)); } // check field names String[] checkNames = { "api_url", "archived", "api_issues_url", "milestones_url", "api_milestones_url", "api_categories_url", "issues_url", "name", "url", "api_people_url", "primary_company_name" }; // project field names String[] fieldNames = JSONObject.getNames(p[0]); int numKeys = p[0].length(); SifterProj[] proj = new SifterProj[arrayLength]; for (int j = 0; j < arrayLength; j++) { proj[j] = new SifterProj(p[j].get("api_url").toString(), p[j].get("archived").toString(), p[j].get("api_issues_url").toString(), p[j].get("milestones_url").toString(), p[j].get("api_milestones_url").toString(), p[j].get("api_categories_url").toString(), p[j].get("issues_url").toString(), p[j].get("name").toString(), p[j].get("url").toString(), p[j].get("api_people_url").toString(), p[j].get("primary_company_name").toString()); System.out.println("************ project: " + (j + 1) + " ************"); for (int i = 0; i < numKeys; i++) { System.out.print(fieldNames[i]); System.out.print(" : "); System.out.println(p[j].get(fieldNames[i])); } } }
From source file:ReaderIter.java
public static void main(String[] args) throws IOException { // The RE pattern Pattern patt = Pattern.compile("[A-Za-z][a-z]+"); // A FileReader (see the I/O chapter) BufferedReader r = new BufferedReader(new FileReader("ReaderIter.java")); // For each line of input, try matching in it. String line;// ww w.jav a 2s. co m while ((line = r.readLine()) != null) { // For each match in the line, extract and print it. Matcher m = patt.matcher(line); while (m.find()) { // Simplest method: // System.out.println(m.group(0)); // Get the starting position of the text int start = m.start(0); // Get ending position int end = m.end(0); // Print whatever matched. // Use CharacterIterator.substring(offset, end); System.out.println(line.substring(start, end)); } } }
From source file:postenergy.TestHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin"); try {/*from w w w .j a v a 2 s.c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("Email", "youremail")); nameValuePairs.add(new BasicNameValuePair("Passwd", "yourpassword")); nameValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE")); nameValuePairs.add(new BasicNameValuePair("source", "Google-cURL-Example")); nameValuePairs.add(new BasicNameValuePair("service", "ac2dm")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Auth=")) { String key = line.substring(5); // do something with the key } } } catch (IOException e) { e.printStackTrace(); } }
From source file:CatFile.java
public static void main(String[] av) { CatFile c = new CatFile(); if (av.length == 0) c.process(new BufferedReader(new InputStreamReader(System.in))); else//from w w w . j a va 2s . c o m for (int i = 0; i < av.length; i++) try { c.process(new BufferedReader(new FileReader(av[i]))); } catch (FileNotFoundException e) { System.err.println(e); } }