List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:FileList.java
public static void main(String[] args) { final int assumedLineLength = 50; File file = new File(args[0]); List<String> fileList = new ArrayList<String>((int) (file.length() / assumedLineLength) * 2); BufferedReader reader = null; int lineCount = 0; try {//from ww w . ja va 2 s .c o m reader = new BufferedReader(new FileReader(file)); for (String line = reader.readLine(); line != null; line = reader.readLine()) { fileList.add(line); lineCount++; } } catch (IOException e) { System.err.format("Could not read %s: %s%n", file, e); System.exit(1); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } int repeats = Integer.parseInt(args[1]); Random random = new Random(); for (int i = 0; i < repeats; i++) { System.out.format("%d: %s%n", i, fileList.get(random.nextInt(lineCount - 1))); } }
From source file:com.jdom.mediadownloader.MediaDownloader.java
public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException( "You must pass the location to the properties file to the application!"); }// w w w . j a va2 s . c o m File file = new File(args[0]); Properties properties = new Properties(); FileReader fileReader = null; try { fileReader = new FileReader(file); properties.load(fileReader); } catch (Exception e) { throw new RuntimeException(e); } finally { Closeables.closeQuietly(fileReader); } System.getProperties().putAll(properties); initializeContext(); MediaDownloader mediaDownloader = ctx.getBean(MediaDownloader.class); mediaDownloader.processDownloads(); }
From source file:org.datagator.api.client.SimpleMatrix.java
public static void main(String[] args) throws IOException { FileReader reader = new FileReader("../../data/json/IGO_Weighted_Dyad.json"); SimpleMatrix matrix = (SimpleMatrix) Entity.create(reader); // empty matrix //Matrix matrix = (SimpleMatrix) Entity.create(new java.io.StringReader( // "{\"kind\": \"datagator#SimpleMatrix\", \"columnHeaders\": 0, " + // "\"rowHeaders\": 0, \"rows\": [[]], \"rowsCount\": 1, " + // "\"columnsCount\": 0}")); System.out.println(matrix.kind); System.out.println(Integer.toString(matrix.rowsCount)); System.out.println(Integer.toString(matrix.columnsCount)); }
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);//from w w w .j a va 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:RhymingWords.java
public static void main(String[] args) throws IOException { FileReader words = new FileReader("words.txt"); // do the reversing and sorting Reader rhymedWords = reverse(sort(reverse(words))); // write new list to standard out BufferedReader in = new BufferedReader(rhymedWords); String input;//w ww. j a va2 s.co m while ((input = in.readLine()) != null) System.out.println(input); in.close(); }
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;/*w w w . ja v a2s. 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:azkaban.jobtype.HadoopSecureHiveWrapper.java
public static void main(final String[] args) throws Exception { String propsFile = System.getenv(ProcessJob.JOB_PROP_ENV); Properties prop = new Properties(); prop.load(new BufferedReader(new FileReader(propsFile))); hiveScript = prop.getProperty("hive.script"); final Configuration conf = new Configuration(); UserGroupInformation.setConfiguration(conf); securityEnabled = UserGroupInformation.isSecurityEnabled(); if (shouldProxy(prop)) { UserGroupInformation proxyUser = null; String userToProxy = prop.getProperty("user.to.proxy"); if (securityEnabled) { String filelocation = System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION); if (filelocation == null) { throw new RuntimeException("hadoop token information not set."); }//from w ww.j a va 2s. c om if (!new File(filelocation).exists()) { throw new RuntimeException("hadoop token file doesn't exist."); } logger.info("Found token file " + filelocation); logger.info("Setting " + HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY + " to " + filelocation); System.setProperty(HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY, filelocation); UserGroupInformation loginUser = null; loginUser = UserGroupInformation.getLoginUser(); logger.info("Current logged in user is " + loginUser.getUserName()); logger.info("Creating proxy user."); proxyUser = UserGroupInformation.createProxyUser(userToProxy, loginUser); for (Token<?> token : loginUser.getTokens()) { proxyUser.addToken(token); } } else { proxyUser = UserGroupInformation.createRemoteUser(userToProxy); } logger.info("Proxied as user " + userToProxy); proxyUser.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { runHive(args); return null; } }); } else { logger.info("Not proxying. "); runHive(args); } }
From source file:com.msopentech.odatajclient.engine.performance.PerfTestReporter.java
public static void main(final String[] args) throws Exception { // 1. check input directory final File reportdir = new File(args[0] + File.separator + "target" + File.separator + "surefire-reports"); if (!reportdir.isDirectory()) { throw new IllegalArgumentException("Expected directory, got " + args[0]); }/*from w w w . j a va 2 s . com*/ // 2. read test data from surefire output final File[] xmlReports = reportdir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.endsWith("-output.txt"); } }); final Map<String, Map<String, Double>> testData = new TreeMap<String, Map<String, Double>>(); for (File xmlReport : xmlReports) { final BufferedReader reportReader = new BufferedReader(new FileReader(xmlReport)); try { while (reportReader.ready()) { String line = reportReader.readLine(); final String[] parts = line.substring(0, line.indexOf(':')).split("\\."); final String testClass = parts[0]; if (!testData.containsKey(testClass)) { testData.put(testClass, new TreeMap<String, Double>()); } line = reportReader.readLine(); testData.get(testClass).put(parts[1], Double.valueOf(line.substring(line.indexOf(':') + 2, line.indexOf('[')))); } } finally { IOUtils.closeQuietly(reportReader); } } // 3. build XSLX output (from template) final HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(args[0] + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + XLS)); for (Map.Entry<String, Map<String, Double>> entry : testData.entrySet()) { final Sheet sheet = workbook.getSheet(entry.getKey()); int rows = 0; for (Map.Entry<String, Double> subentry : entry.getValue().entrySet()) { final Row row = sheet.createRow(rows++); Cell cell = row.createCell(0); cell.setCellValue(subentry.getKey()); cell = row.createCell(1); cell.setCellValue(subentry.getValue()); } } final FileOutputStream out = new FileOutputStream( args[0] + File.separator + "target" + File.separator + XLS); try { workbook.write(out); } finally { IOUtils.closeQuietly(out); } }
From source file:codingchallenge.SortableChallenge.java
public static void main(String[] args) throws Exception { if (args.length != 2) { usage();/*from ww w .ja v a 2s . c o m*/ } String productsFileName = args[0]; String listingsFileName = args[1]; Reader productsReader = new FileReader(productsFileName); Reader listingsReader = new FileReader(listingsFileName); new SortableChallenge(productsReader, listingsReader).run(); }
From source file:com.aestel.chemistry.openEye.fp.DistMatrix.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.tsv from FingerPrinter]"); opt.setRequired(true);/* ww w . j av a2 s. co m*/ options.addOption(opt); opt = new Option("o", true, "outpur file [.tsv "); opt.setRequired(true); 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 != 0) exitWithHelp(options); String file = cmd.getOptionValue("i"); BufferedReader in = new BufferedReader(new FileReader(file)); file = cmd.getOptionValue("o"); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file))); ArrayList<Fingerprint> fps = new ArrayList<Fingerprint>(); ArrayList<String> ids = new ArrayList<String>(); String line; while ((line = in.readLine()) != null) { String[] parts = line.split("\t"); if (parts.length == 3) { ids.add(parts[0]); fps.add(new ByteFingerprint(parts[2])); } } in.close(); out.print("ID"); for (int i = 0; i < ids.size(); i++) { out.print('\t'); out.print(ids.get(i)); } out.println(); for (int i = 0; i < ids.size(); i++) { out.print(ids.get(i)); Fingerprint fp1 = fps.get(i); for (int j = 0; j <= i; j++) { out.printf("\t%.4g", fp1.tanimoto(fps.get(j))); } out.println(); } out.close(); System.err.printf("Done %d fingerprints in %.2gsec\n", fps.size(), (System.currentTimeMillis() - start) / 1000D); }