List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:featureExtractor.popularityMeasure.java
public static void main(String[] args) throws IOException { //ReadKnownPopularityScores(); FileWriter fw = new FileWriter(Out_resultFile); BufferedWriter bw = new BufferedWriter(fw); FileReader inputFile = new FileReader(In_entities); BufferedReader bufferReader = new BufferedReader(inputFile); String line;//from w w w .j a va 2s . co m while ((line = bufferReader.readLine()) != null) { String[] row = line.split("\t"); double score = 0; String entityName = row[0].toLowerCase().trim(); System.out.println("Searching for : " + entityName); if (knownScore_table.containsKey(entityName)) { //System.out.println("Already known for: " + entityName); score = knownScore_table.get(entityName); } else { System.out.println("Not known for: " + entityName); String json = searchTest(entityName, "&scoring=entity"); try { score = ParseJSON_getScore(json); } catch (Exception e) { score = 0; } System.out.println("Putting : " + entityName); knownScore_table.put(entityName, score); } bw.write(row[0] + "\t" + score + "\n"); System.out.println(row[0]); } bw.close(); }
From source file:org.lieuofs.extraction.etatpays.ExtractionPays.java
/** * @param args/*from w w w . ja v a 2 s . c o m*/ */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "beans_lieuofs.xml" }); EtatTerritoireCritere critere = new EtatTerritoireCritere(); //critere.setEstEtat(Boolean.FALSE); EtatTerritoireDao dao = (EtatTerritoireDao) context.getBean("etatTerritoireDao"); Set<EtatTerritoirePersistant> etats = dao.rechercher(critere); EtatWriter etatWriter = new NumOFSEtatWriter(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("ExtractionPaysOFSReconnuRecemment.txt"), "UTF-8")); List<EtatTerritoirePersistant> listeTriee = new ArrayList<EtatTerritoirePersistant>(etats); Collections.sort(listeTriee, new Comparator<EtatTerritoirePersistant>() { @Override public int compare(EtatTerritoirePersistant o1, EtatTerritoirePersistant o2) { //return o1.getFormeCourte("fr").compareTo(o2.getFormeCourte("fr")); return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); for (EtatTerritoirePersistant etat : filtre(listeTriee)) { String etatStr = etatWriter.ecrireEtat(etat); if (null != etatStr) { writer.append(etatStr); } } writer.close(); }
From source file:org.lieuofs.extraction.commune.historisation.ExtractionNumHistorisationCommune.java
/** * @param args/*from w w w. ja va2s . com*/ */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "beans_lieuofs.xml" }); CommuneCritere critere = new CommuneCritere(); IGestionCommune gestionnaire = (IGestionCommune) context.getBean("gestionCommune"); List<ICommuneSuisse> communes = gestionnaire.rechercher(critere); Collections.sort(communes, new Comparator<ICommuneSuisse>() { public int compare(ICommuneSuisse com1, ICommuneSuisse com2) { return com1.getNumeroOFS() - com2.getNumeroOFS(); } }); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("NumeroHistorisationCommune.sql"), "Windows-1252")); NumeroHistorisationCommuneWriter commWriter = new NumeroHistorisationRefonteSQLWriter(); for (ICommuneSuisse commune : communes) { String numHistStr = commWriter.ecrireNumero(commune); if (null != numHistStr) { writer.append(numHistStr); } } writer.close(); }
From source file:edu.internet2.middleware.psp.names.CreateLdapNames.java
/** * @param args//from ww w. j a v a 2 s. c o m */ public static void main(String[] args) { try { BufferedWriter writer = new BufferedWriter(new FileWriter("/tmp/people.ldif")); RandomCollection<String> givenNames = readGivenNames(); RandomCollection<String> surnames = readSurnames(); for (int i = 0; i < 1000; i++) { String surname = surnames.next(); String givenName = givenNames.next(); String ldif = getLdif(i, givenName, surname); // System.out.println(ldif); writer.write(ldif); writer.write("\n"); } writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:BufferedCopy.java
public static void main(String[] args) throws IOException { BufferedReader inputStream = null; BufferedWriter outputStream = null; try {//ww w .j av a2s .c o m inputStream = new BufferedReader(new FileReader("xanadu.txt")); outputStream = new BufferedWriter(new FileWriter("characteroutput.txt")); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } }
From source file:org.jfree.chart.demo.Display.java
/** * Launch the application./* w w w.j a va 2s. c o m*/ */ public static void main(String[] args) throws IOException { EventQueue.invokeLater(new Runnable() { public void run() { try { Display window = new Display(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } //////////// } }); try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s; File dataFile = new File("data.txt"); FileWriter fw = new FileWriter(dataFile); BufferedWriter bw = new BufferedWriter(fw); DataParser datIn = new DataParser(effectiveX, effectiveY); //while(!enabled){}//spin until enabled while ((s = in.readLine()) != null && s.length() != 0 && enabled) { // System.out.println(s); if (datIn.parseString(s)) { bw.write(s); bw.write('\n'); bw.flush(); panel_1.plotCoords(datIn.getX(), datIn.getFlippedY()); TimeElapsed.setText(Double.toString(datIn.getTime())); } } bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java
public static void main(String[] args) throws IOException { String host = args[0];/*w w w .ja v a 2 s . co m*/ int port = Integer.parseInt(args[1]); Jedis jedis = new Jedis(host, port, 20000); // Cluster to binary tree visualitzation Map<String, String> attr_cluster = jedis.hgetAll("ClusterBinaryTree-Arrel"); String cluster_name = attr_cluster.get("cluster_ids_name"); JSONObject cluster; if (!cluster_name.equals("cluster_splited")) { cluster = new JSONObject(); cluster.put("name", "arrel"); } else { String id_left_centroid = attr_cluster.get("id_left_centroid"); String id_right_centroid = attr_cluster.get("id_right_centroid"); String hash_left = attr_cluster.get("hash_left"); String hash_right = attr_cluster.get("hash_right"); cluster = new JSONObject(); cluster.put("name", "arrel"); cluster.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis, id_right_centroid, hash_right)); } jedis.disconnect(); Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("data_toVisualize/cluster.json"), "UTF-8")); try { out.write(cluster.toJSONString()); } finally { out.close(); } }
From source file:com.opengamma.bbg.loader.BloombergSwaptionFileLoader.java
/** * Little util to parse swaption tickers into a csv for further analysis. * @param args command line params//from w w w . j a va2 s .c om */ public static void main(String[] args) { // CSIGNORE CSVReader csvReader = null; CSVWriter csvWriter = null; try { csvReader = new CSVReader(new BufferedReader(new FileReader(args[0]))); csvWriter = new CSVWriter(new BufferedWriter(new FileWriter(args[1]))); String[] line; Pattern pattern = Pattern.compile("^(\\w\\w\\w).*?(\\d+)(M|Y)(\\d+)(M|Y)\\s*?(PY|RC)\\s*?(.*)$"); BloombergReferenceDataProvider rawBbgRefDataProvider = getBloombergSecurityFileLoader(); MongoDBValueCachingReferenceDataProvider bbgRefDataProvider = MongoCachedReferenceData .makeMongoProvider(rawBbgRefDataProvider, BloombergSwaptionFileLoader.class); while ((line = csvReader.readNext()) != null) { String name = line[NAME_FIELD]; Matcher matcher = pattern.matcher(name); if (matcher.matches()) { String ccy = matcher.group(1); String swapTenorSize = matcher.group(2); String swapTenorUnit = matcher.group(3); String optionTenorSize = matcher.group(4); String optionTenorUnit = matcher.group(5); String payReceive = matcher.group(6); String distanceATM = matcher.group(7); String buid = "/buid/" + line[BUID_FIELD]; String value = bbgRefDataProvider.getReferenceDataValue(buid, "TICKER"); csvWriter.writeNext(new String[] { name, ccy, swapTenorSize, swapTenorUnit, optionTenorSize, optionTenorUnit, payReceive, distanceATM, value }); } else { s_logger.error("Couldn't parse " + name + " field"); } } } catch (IOException ioe) { s_logger.error("Error while reading file", ioe); } finally { IOUtils.closeQuietly(csvReader); IOUtils.closeQuietly(csvWriter); } }
From source file:org.lieuofs.extraction.etatpays.ExtractionEtat.java
/** * @param args// w w w. ja va2 s .co m */ public static void main(String[] args) throws IOException { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "beans_lieuofs.xml" }); EtatTerritoireCritere critere = new EtatTerritoireCritere(); critere.setEstEtat(Boolean.TRUE); // critere.setValide(Boolean.TRUE); EtatTerritoireDao dao = (EtatTerritoireDao) context.getBean("etatTerritoireDao"); Set<EtatTerritoirePersistant> etats = dao.rechercher(critere); EtatWriter etatWriter = new CsvPlatEtatWriter(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("Etat.txt"), "UTF-8")); List<EtatTerritoirePersistant> listeTriee = new ArrayList<EtatTerritoirePersistant>(etats); Collections.sort(listeTriee, new Comparator<EtatTerritoirePersistant>() { @Override public int compare(EtatTerritoirePersistant o1, EtatTerritoirePersistant o2) { //return o1.getFormeCourte("fr").compareTo(o2.getFormeCourte("fr")); return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); for (EtatTerritoirePersistant etat : listeTriee) { String etatStr = etatWriter.ecrireEtat(etat); if (null != etatStr) { writer.append(etatStr); } } writer.close(); }
From source file:MyTerrierClass.java
public static void main(String[] args) throws InterruptedException, IOException { System.gc();/*from w w w . j ava 2 s.c o m*/ System.setProperty("terrier.home", "/home/manan/Downloads/terrier-4.0"); System.setProperty("terrier.etc", "/home/manan/Downloads/terrier-4.0/etc"); System.setProperty("terrier.setup", "/home/manan/Downloads/terrier-4.0/etc/terrier.properties"); bw = new BufferedWriter(new FileWriter("/home/manan/terrier_trials/myOutput.txt", false)); bw.write("#######OUTPUT#######"); List<String> cl = new ArrayList<>(); cl.add("/home/manan/wiki-small/"); SimpleFileCollection sf = new SimpleFileCollection(cl, true); print("sf list size b4 indexing:" + sf.getFileList().size()); Indexer indexer = new BlockIndexer("/home/manan/terrier_trials/", ".trial"); indexer.index(new Collection[] { sf }); print("sf list size after indexing:" + sf.getFileList().size()); sf.reset(); //get document reader Reader reader = sf.next().getReader(); //print all tokens Tokeniser tokeniser = Tokeniser.getTokeniser(); TokenStream ts = tokeniser.tokenise(reader); while (ts.hasNext()) { System.out.println(ts.next()); } // Index index = Index.createIndex(); // // Manager queryingManager = new Manager(index); // // String query = "name quick"; // SearchRequest srq = queryingManager.newSearchRequest("queryID0", query); // srq.addMatchingModel("Matching", "PL2"); // queryingManager.runPreProcessing(srq); // queryingManager.runMatching(srq); // queryingManager.runPostProcessing(srq); // queryingManager.runPostFilters(srq); // ResultSet rs = srq.getResultSet(); // for(int each : rs.getDocids()) // System.out.println("docids: "+ each); // Index index = Index.createIndex(); // Lexicon<String> lex = index.getLexicon(); // print("lex number of entries: "+lex.numberOfEntries()); // String myTerm = "name"; // LexiconEntry le = lex.getLexiconEntry(myTerm); // if(le!=null) // { // print(myTerm+" in number of docs: "+le.getDocumentFrequency()); // print(myTerm+" occurance times: "+le.getFrequency()); // } // else // { // print(myTerm+" not found"); // } // Index index = Index.createIndex(); // BitPostingIndex inv = (BitPostingIndex) index.getInvertedIndex(); // MetaIndex meta = index.getMetaIndex(); // Lexicon<String> lex = index.getLexicon(); // LexiconEntry le = lex.getLexiconEntry( "name" ); // IterablePosting postings = inv.getPostings((BitIndexPointer) le); // while (postings.next() != IterablePosting.EOL) { // String docno = meta.getItem("docno", postings.getId()); // System.out.println(docno + " with frequency " + postings.getFrequency()); // } bw.close(); }