List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:com.tmo.swagger.main.GenrateSwaggerJson.java
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException, EmptyXlsRows { PropertyReader pr = new PropertyReader(); Properties prop = pr.readPropertiesFile(args[0]); //Properties prop =pr.readClassPathPropertyFile("common.properties"); String swaggerFile = prop.getProperty("swagger.json"); String sw = ""; if (swaggerFile != null && swaggerFile.length() > 0) { Swagger swagger = populatePropertiesOnlyPaths(prop, new SwaggerParser().read(swaggerFile)); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); sw = mapper.writeValueAsString(swagger); } else {/*from ww w. ja v a2 s .c o m*/ ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); Swagger swagger = populateProperties(prop); sw = mapper.writeValueAsString(swagger); } try { File file = new File(args[1] + prop.getProperty("path.operation.tags") + ".json"); //File file = new File("src/main/resources/"+prop.getProperty("path.operation.tags")+".json"); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(sw); logger.info("Swagger Genration Done!"); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:it.sardegnaricerche.voiceid.sr.Voiceid.java
public static void main(String[] args) { logger.info("Voiceid main method"); logger.info("First argument: '" + args[0] + "'"); long startTime = System.currentTimeMillis(); Voiceid voiceid = null;//w w w.j a v a 2 s .c om GMMVoiceDB db = null; try { db = new GMMVoiceDB(args[1], new UBMModel(args[0])); File f = new File(args[2]); voiceid = new Voiceid(db, f, new LIUMStandardDiarizator()); voiceid.extractClusters(); voiceid.matchClusters(); // voiceid.toWav(); // voiceid.printClusters(); JSONObject obj = voiceid.toJson(); for (VCluster c : voiceid.getClusters()) { logger.info("" + c.getSample().getResource().getAbsolutePath()); } // FileWriter fstream = new // FileWriter(f.getAbsolutePath().replaceFirst("[.][^.]+$", "") + // ".json"); String filename = Utils.getBasename(f) + ".json"; FileWriter fstream = new FileWriter(filename); BufferedWriter out = new BufferedWriter(fstream); out.write(obj.toString()); // Close the output stream out.close(); // voiceid.makeAllModels(); } catch (IOException e) { logger.severe(e.getMessage()); } catch (Exception ex) { logger.severe(ex.getMessage()); } long endTime = System.currentTimeMillis(); long duration = endTime - startTime; logger.info("Exit (" + ((float) duration / 1000) + " s)"); // logger.info("Max Threads: " + (int) db.maxThreads); }
From source file:experiments.SimpleExample.java
/** * Starts the example.//from w ww.j ava 2 s. c o m * * @param args * if optional first argument provided, it represents the number * of bits to use, but no more than 32 * * @author Neil Rotstan * @author Klaus Meffert * @throws IOException * @since 2.0 */ public static void main(String[] args) throws IOException { SimpleExample se = new SimpleExample(); try { File[] result = { new File("ga_x.txt"), new File("ga_cos.txt"), new File("ga_ackley.txt"), new File("ga_quar.txt"), new File("ga_step.txt"), new File("ga_rosen.txt"), new File("ga_sch.txt"), new File("ga_gri.txt"), new File("ga_pen1.txt"), new File("ga_pen2.txt"), new File("ga_wei.txt"), new File("ga_non.txt") }; BufferedWriter[] output = new BufferedWriter[result.length]; for (int i = 0; i <= result.length - 1; i++) { if (result[i].exists()) { result[i].delete(); if (result[i].createNewFile()) { System.out.println("result" + i + " file create success!"); } else { System.out.println("result" + i + " file create failed!"); } } else { if (result[i].createNewFile()) { System.out.println("result" + i + " file create success!"); } else { System.out.println("result" + i + " file create failed!"); } } output[i] = new BufferedWriter(new FileWriter(result[i])); } for (int a = 0; a <= 0; a++) { // se.runga(100, 30, 40, -100, 100, new MaxFunction(), output[0]); // se.runga(200, 30, 40, -100, 100, new MaxFunction(), output[0]); // se.runga(120, 30, 40, -5.12, 5.12, new CosMaxFunction(), output[1]); // se.runga(200, 30, 40, -5.12, 5.12, new CosMaxFunction(), output[1]); // se.runga(120, 30, 40, -32, 32, new AckleyMaxFunction(), output[2]); se.runga(2000, 30, 40, -32, 32, new AckleyMaxFunction(), output[2]); // se.runga(120, 30, 40, -100, 100, new QuardircMaxFunction(), output[3]); // se.runga(200, 30, 40, -100, 100, new QuardircMaxFunction(), output[3]); // se.runga(120, 30, 40, -100, 100, new StepMaxFunction(), output[4]); // se.runga(200, 30, 40, -100, 100, new StepMaxFunction(), output[4]); // se.runga(120, 30, 40, -30, 30, new RosenbrockMaxFunction(), output[5]); // se.runga(200, 30, 40, -30, 30, new RosenbrockMaxFunction(), output[5]); // se.runga(120, 30, 40, -500, 500, new SchwefelMaxFunction(), output[6]); // se.runga(200, 30, 40, -500, 500, new SchwefelMaxFunction(), output[6]); // se.runga(120, 30, 40, -600, 600, new GriewankMaxFunction(), output[7]); // se.runga(200, 30, 40, -600, 600, new GriewankMaxFunction(), output[7]); // se.runga(120, 30, 40, -50, 50, new PenalizedMaxFunction(), output[8]); // se.runga(200, 30, 40, -50, 50, new PenalizedMaxFunction(), output[8]); // se.runga(120, 30, 40, -50, 50, new Penalized2MaxFunction(), output[9]); // se.runga(200, 30, 40, -50, 50, new Penalized2MaxFunction(), output[9]); // se.runga(120, 30, 40, -5.12, 5.12, new WeiMaxFunction(), output[10]); // se.runga(200, 30, 40, -5.12, 5.12, new WeiMaxFunction(), output[10]); // se.runga(120, 30, 40, -0.5, 0.5, new NonMaxFunction(), output[11]); // se.runga(200, 30, 40, -0.5, 0.5, new NonMaxFunction(), output[11]); for (BufferedWriter op : output) { op.write("\n"); op.flush(); } } for (BufferedWriter op : output) { op.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:akori.Impact.java
static public void main(String[] args) throws IOException { String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\"; String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\"; for (int i = 1; i <= 32; ++i) { for (int k = 1; k <= 15; ++k) { System.out.println("Matrix " + i + "-" + k); BufferedImage img = null; try { img = ImageIO.read(new File(PATHIMG + i + ".png")); } catch (IOException ex) { ex.getStackTrace();/*from w w w .j a va2 s . co m*/ } int ymax = img.getHeight(); int xmax = img.getWidth(); double[][] imagen = new double[ymax][xmax]; BufferedReader in = null; try { in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt")); } catch (FileNotFoundException ex) { ex.getStackTrace(); } String linea; ArrayList<String> lista = new ArrayList<String>(); HashMap<String, String> lista1 = new HashMap<String, String>(); try { for (int j = 0; (linea = in.readLine()) != null; ++j) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[1]); int y = (int) Double.parseDouble(datos[2]); if (x >= xmax || y >= ymax || x <= 0 || y <= 0) { continue; } lista.add(x + "," + y); } } catch (Exception ex) { ex.getStackTrace(); } try { in.close(); } catch (IOException ex) { ex.getStackTrace(); } Iterator iter = lista.iterator(); int[][] matrix = new int[lista.size()][2]; for (int j = 0; iter.hasNext(); ++j) { String xy = (String) iter.next(); String[] datos = xy.split(","); matrix[j][0] = Integer.parseInt(datos[0]); matrix[j][1] = Integer.parseInt(datos[1]); } for (int j = 0; j < matrix.length; ++j) { int std = 50; int x = matrix[j][0]; int y = matrix[j][1]; imagen[y][x] += 1; double aux; normalMatrix(imagen, y, x, std); } FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt"); BufferedWriter bw = new BufferedWriter(fw); for (int j = 0; j < imagen.length; ++j) { for (int t = 0; t < imagen[j].length; ++t) { if (t + 1 == imagen[j].length) bw.write(imagen[j][t] + ""); else bw.write(imagen[j][t] + ","); } bw.write("\n"); } bw.close(); } } }
From source file:com.termmed.sampling.ConceptsWithMoreThanThreeRoleGroups.java
/** * The main method.// w w w . java2s .c o m * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { System.out.println("Starting..."); Map<String, Set<String>> groupsMap = new HashMap<String, Set<String>>(); File relsFile = new File( "/Users/alo/Downloads/SnomedCT_RF2Release_INT_20160131-1/Snapshot/Terminology/sct2_Relationship_Snapshot_INT_20160131.txt"); BufferedReader br2 = new BufferedReader(new FileReader(relsFile)); String line2; int count2 = 0; while ((line2 = br2.readLine()) != null) { // process the line. count2++; if (count2 % 10000 == 0) { //System.out.println(count2); } List<String> columns = Arrays.asList(line2.split("\t", -1)); if (columns.size() >= 6) { if (columns.get(2).equals("1") && !columns.get(6).equals("0")) { if (!groupsMap.containsKey(columns.get(4))) { groupsMap.put(columns.get(4), new HashSet<String>()); } groupsMap.get(columns.get(4)).add(columns.get(6)); } } } System.out.println("Relationship groups loaded"); Gson gson = new Gson(); System.out.println("Reading JSON 1"); File crossoverFile1 = new File("/Users/alo/Downloads/crossover_role_to_group.json"); String contents = FileUtils.readFileToString(crossoverFile1, "utf-8"); Type collectionType = new TypeToken<Collection<ControlResultLine>>() { }.getType(); List<ControlResultLine> lineObject = gson.fromJson(contents, collectionType); Set<String> crossovers1 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject) { crossovers1.add(loopResult.conceptId); } System.out.println("Crossovers 1 loaded, " + lineObject.size() + " Objects"); System.out.println("Reading JSON 2"); File crossoverFile2 = new File("/Users/alo/Downloads/crossover_group_to_group.json"); String contents2 = FileUtils.readFileToString(crossoverFile2, "utf-8"); List<ControlResultLine> lineObject2 = gson.fromJson(contents2, collectionType); Set<String> crossovers2 = new HashSet<String>(); for (ControlResultLine loopResult : lineObject2) { crossovers2.add(loopResult.conceptId); } System.out.println("Crossovers 2 loaded, " + lineObject2.size() + " Objects"); Set<String> foundConcepts = new HashSet<String>(); int count3 = 0; BufferedWriter writer = new BufferedWriter( new FileWriter(new File("ConceptsWithMoreThanThreeRoleGroups.csv"))); ; for (String loopConcept : groupsMap.keySet()) { if (groupsMap.get(loopConcept).size() > 3) { writer.write(loopConcept); writer.newLine(); foundConcepts.add(loopConcept); count3++; } } writer.close(); System.out.println("Found " + foundConcepts.size() + " concepts"); int countCrossover1 = 0; for (String loopConcept : foundConcepts) { if (crossovers1.contains(loopConcept)) { countCrossover1++; } } System.out.println(countCrossover1 + " are present in crossover_role_to_group"); int countCrossover2 = 0; for (String loopConcept : foundConcepts) { if (crossovers2.contains(loopConcept)) { countCrossover2++; } } System.out.println(countCrossover2 + " are present in crossover_group_to_group"); System.out.println("Done"); }
From source file:immf.EmojiUtil.java
public static void main(String[] args) { BufferedWriter br = null; try {// ww w. j a v a 2s . c o m br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("./emoji.html"), "UTF-8")); br.write("<html>" + "<head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + "</head>" + "<body>" + ServerMain.Version + "<br><br>" + "<table>"); br.write("<th>Unicode</th><th>?</th><th></th>"); for (Emoji e : map.values()) { br.write("<tr>\n"); br.write(" <td>" + String.format("0x%x", (int) e.getC()) + "</td>" + "<td><img src='" + emojiToImageUrl(e.getC()) + "'></td>" + "<td>" + e.getLabel() + "</td>\n"); br.write("</tr>\n"); } br.write("</table></body></html>"); br.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.jetwick.snacktory.HtmlFetcher.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new FileReader("urls.txt")); String line = null;//from w w w.ja v a2 s. co m Set<String> existing = new LinkedHashSet<String>(); while ((line = reader.readLine()) != null) { int index1 = line.indexOf("\""); int index2 = line.indexOf("\"", index1 + 1); String url = line.substring(index1 + 1, index2); String domainStr = SHelper.extractDomain(url, true); String counterStr = ""; // TODO more similarities if (existing.contains(domainStr)) counterStr = "2"; else existing.add(domainStr); String html = new HtmlFetcher().fetchAsString(url, 20000); String outFile = domainStr + counterStr + ".html"; BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); writer.write(html); writer.close(); } reader.close(); }
From source file:FileCompressor.java
public static void main(String[] args) throws IOException { String file = "D:\\XJad.rar.txt"; BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedWriter writer = new BufferedWriter(new FileWriter(file + "_out.txt")); StringBuilder content = new StringBuilder(); String tmp;/*from w w w . j a v a 2 s . co m*/ while ((tmp = reader.readLine()) != null) { content.append(tmp); content.append(System.getProperty("line.separator")); } FileCompressor f = new FileCompressor(); writer.write(f.compress(content.toString())); writer.close(); reader.close(); reader = new BufferedReader(new FileReader(file + "_out.txt")); StringBuilder content2 = new StringBuilder(); while ((tmp = reader.readLine()) != null) { content2.append(tmp); content2.append(System.getProperty("line.separator")); } String decompressed = f.decompress(content2.toString()); String c = content.toString(); System.out.println(decompressed.equals(c)); }
From source file:io.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java
public static void main(String[] args) throws Exception { Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv"); Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv"); BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8); BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8); Random rand = new Random(); int sequenceNumber = 0; for (int i = 0; i < 20; i++) { int product = rand.nextInt(10); UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build(); for (int j = 0; j < 20; j++) { double value = rand.nextDouble(); buildData.write("2016010101"); buildData.write('\t'); buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data buildData.write('\t'); buildData.write(Integer.toString(product)); // product dimension buildData.write('\t'); buildData.write(Double.toString(value)); buildData.newLine();/*from w w w. j a va2 s . c o m*/ sketch.update(value); sequenceNumber++; } sketchData.write("2016010101"); sketchData.write('\t'); sketchData.write(Integer.toString(product)); // product dimension sketchData.write('\t'); sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true))); sketchData.newLine(); } buildData.close(); sketchData.close(); }
From source file:de.tudarmstadt.ukp.csniper.resbuild.EvaluationItemFixer.java
public static void main(String[] args) { connect(HOST, DATABASE, USER, PASSWORD); Map<Integer, String> items = new HashMap<Integer, String>(); Map<Integer, String> failed = new HashMap<Integer, String>(); // fetch coveredTexts of dubious items and clean it PreparedStatement select = null; try {//from ww w .j a va2 s .com StringBuilder selectQuery = new StringBuilder(); selectQuery.append("SELECT * FROM EvaluationItem "); selectQuery.append("WHERE LOCATE(coveredText, ' ') > 0 "); selectQuery.append("OR LOCATE('" + LRB + "', coveredText) > 0 "); selectQuery.append("OR LOCATE('" + RRB + "', coveredText) > 0 "); selectQuery.append("OR LEFT(coveredText, 1) = ' ' "); selectQuery.append("OR RIGHT(coveredText, 1) = ' ' "); select = connection.prepareStatement(selectQuery.toString()); log.info("Running query [" + selectQuery.toString() + "]."); ResultSet rs = select.executeQuery(); while (rs.next()) { int id = rs.getInt("id"); String coveredText = rs.getString("coveredText"); try { // special handling of double whitespace: in this case, re-fetch the text if (coveredText.contains(" ")) { coveredText = retrieveCoveredText(rs.getString("collectionId"), rs.getString("documentId"), rs.getInt("beginOffset"), rs.getInt("endOffset")); } // replace bracket placeholders and trim the text coveredText = StringUtils.replace(coveredText, LRB, "("); coveredText = StringUtils.replace(coveredText, RRB, ")"); coveredText = coveredText.trim(); items.put(id, coveredText); } catch (IllegalArgumentException e) { failed.put(id, e.getMessage()); } } } catch (SQLException e) { log.error("Exception while selecting: " + e.getMessage()); } finally { closeQuietly(select); } // write logs BufferedWriter bwf = null; BufferedWriter bws = null; try { bwf = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(LOG_FAILED)), "UTF-8")); for (Entry<Integer, String> e : failed.entrySet()) { bwf.write(e.getKey() + " - " + e.getValue() + "\n"); } bws = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(new File(LOG_SUCCESSFUL)), "UTF-8")); for (Entry<Integer, String> e : items.entrySet()) { bws.write(e.getKey() + " - " + e.getValue() + "\n"); } } catch (IOException e) { log.error("Got an IOException while writing the log files."); } finally { IOUtils.closeQuietly(bwf); IOUtils.closeQuietly(bws); } log.info("Texts for [" + items.size() + "] items need to be cleaned up."); // update the dubious items with the cleaned coveredText PreparedStatement update = null; try { String updateQuery = "UPDATE EvaluationItem SET coveredText = ? WHERE id = ?"; update = connection.prepareStatement(updateQuery); int i = 0; for (Entry<Integer, String> e : items.entrySet()) { int id = e.getKey(); String coveredText = e.getValue(); // update item in database update.setString(1, coveredText); update.setInt(2, id); update.executeUpdate(); log.debug("Updating " + id + " with [" + coveredText + "]"); // show percentage of updated items i++; int part = (int) Math.ceil((double) items.size() / 100); if (i % part == 0) { log.info(i / part + "% finished (" + i + "/" + items.size() + ")."); } } } catch (SQLException e) { log.error("Exception while updating: " + e.getMessage()); } finally { closeQuietly(update); } closeQuietly(connection); }