List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:dylemator.DylematorUI.java
private void writeUserCode() { File userCodes = new File("Kody_osob.txt"); try {//from www . java 2s . c o m BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(userCodes, true)); bufferedWriter.write(this.ud.getCode()); bufferedWriter.newLine(); bufferedWriter.close(); } catch (IOException ex) { Logger.getLogger(DylematorUI.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.elevenpaths.googleindexretriever.GoogleSearch.java
public void export(ArrayList<ArrayList<String>> data, String dork, String nameFile) throws IOException { File file = new File(nameFile); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile();// w w w. j a va 2 s . co m } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write( "<style type=\"text/css\"> table.sample { border-width: 1px; border-spacing: 2px; border-style: outset; border-color: black; border-collapse: separate; background-color: white; } table.sample th { border-width: 1px; padding: 5px; border-style: inset; border-color: green; background-color: white; } table.sample td { border-width: 1px; padding: 5px; border-style: inset; border-color: green; background-color: white; }</style>"); bw.newLine(); bw.write("<h1>#Dork: <font color=blue>" + dork + "</font><br>#Total: <font color=blue>" + data.size() + "</font></h1>"); bw.write( "<table class=sample><tr><td><font color=blue>Words</font></td><td><font color=blue>Sentences</font></td></tr>");// Start table for (ArrayList<String> ds : data) { bw.write("<tr>"); for (String row : ds) { if (!row.isEmpty()) { bw.write("<td>" + escapeHtml4(row) + "</td>"); bw.newLine(); } } bw.write("</tr>"); } bw.write("</table>"); bw.close(); fw.close(); }
From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.graph.PersistentAdjacencyMatrix.java
/** * Saves the adjacency data into a file. * Each line contains the indices of the children of the entity whose index corresponds * to the line's number (starting from 0) *///from ww w . j ava 2 s .co m private void saveAdjacencies() { logger.info("Saving adjacencies..."); try { // Create file FileWriter fstream = new FileWriter("PersistentAdjacencies" + "_" + resourceName); BufferedWriter out = new BufferedWriter(fstream); for (int row = 0; row < resourceSize; row++) { // find which entity has the current index: Entity entity = indexToEntity.get(row); Set<Entity> children = lexSemResource.getChildren(entity); // if the entity has children, find their indices and write them down: if (children.size() != 0) { for (Entity child : children) { int childIndex = entityIndex.get(child); out.write(childIndex + " "); } } // the next entity will come in the next line: out.newLine(); // print progress if (row % 10000 == 0) { logger.info("Progress: " + (100 * row / resourceSize) + "%"); } } //Close the output stream out.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } logger.info("Adjacencies saved to file.\n"); }
From source file:org.matsim.counts.algorithms.CountSimComparisonKMLWriter.java
/** * Creates the CountsErrorGraph for all the data * @param kmlFilename the filename of the kml file * @param visible true if initially visible * @return the ScreenOverlay Feature/*from w w w . j a v a2 s. c o m*/ */ private ScreenOverlayType createBiasErrorGraph(String kmlFilename) { BiasErrorGraph ep = new BiasErrorGraph(this.countComparisonFilter.getCountsForHour(null), this.iterationNumber, null, "error graph"); ep.createChart(0); double[] meanError = ep.getMeanRelError(); double[] meanBias = ep.getMeanAbsBias(); int index = kmlFilename.lastIndexOf(System.getProperty("file.separator")); if (index == -1) { index = kmlFilename.lastIndexOf('/'); } String outdir; if (index == -1) { outdir = ""; } else { outdir = kmlFilename.substring(0, index) + System.getProperty("file.separator"); } String file = outdir + "biasErrorGraphData.txt"; log.info("writing chart data to " + new File(file).getAbsolutePath()); try { BufferedWriter bwriter = IOUtils.getBufferedWriter(file); StringBuilder buffer = new StringBuilder(200); buffer.append("hour \t mean relative error \t mean absolute bias"); bwriter.write(buffer.toString()); bwriter.newLine(); for (int i = 0; i < meanError.length; i++) { buffer.delete(0, buffer.length()); buffer.append(i + 1); buffer.append('\t'); buffer.append(meanError[i]); buffer.append('\t'); buffer.append(meanBias[i]); bwriter.write(buffer.toString()); bwriter.newLine(); } bwriter.close(); } catch (IOException e) { e.printStackTrace(); } String filename = "errorGraphErrorBias.png"; try { writeChartToKmz(filename, ep.getChart()); return createOverlayBottomRight(filename, "Error Graph [Error/Bias]"); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.redsqirl.workflow.server.ActionManager.java
/** * List (cannonical class names) all the classes extending DataflowAction. * /*from w ww. j av a 2 s. c o m*/ * If possible, the classes will be read from a file. If not a file will be written for next time. * * @see com.idiro.BlockManager#getNonAbstractClassesFromSuperClass(String) * @return The classes that extends DataflowAction */ private List<String> getDataflowActionClasses() { File dataFlowActionClassFile = new File(WorkflowPrefManager.getPathDataFlowActionClasses()); List<String> dataFlowActionClassName = new LinkedList<String>(); if (dataFlowActionClassFile.exists()) { //logger.info("getDataflowActionClasses exist"); try { BufferedReader br = new BufferedReader(new FileReader(dataFlowActionClassFile)); String line = null; while ((line = br.readLine()) != null) { dataFlowActionClassName.add(line); } br.close(); } catch (Exception e) { logger.error("Error while reading class file", e); dataFlowActionClassFile.delete(); } } if (!dataFlowActionClassFile.exists()) { //logger.info("getDataflowActionClasses not exist"); dataFlowActionClassName = WorkflowPrefManager.getInstance() .getNonAbstractClassesFromSuperClass(DataflowAction.class.getCanonicalName()); try { BufferedWriter bw = new BufferedWriter(new FileWriter(dataFlowActionClassFile)); Iterator<String> dataoutputClassNameIt = dataFlowActionClassName.iterator(); while (dataoutputClassNameIt.hasNext()) { bw.write(dataoutputClassNameIt.next()); bw.newLine(); } bw.close(); //Everyone can remove this file dataFlowActionClassFile.setReadable(true, false); dataFlowActionClassFile.setWritable(true, false); } catch (Exception e) { logger.error("Error while writing class file", e); dataFlowActionClassFile.delete(); } } logger.debug("Return data flow classes: " + dataFlowActionClassName); return dataFlowActionClassName; }
From source file:matrix.CreateUserList.java
public void tweetsToUserList() throws FileNotFoundException, UnsupportedEncodingException, IOException, ParseException { File fout = new File(userListPathOutput); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); BufferedReader inputTW = new BufferedReader( new InputStreamReader(new FileInputStream(tweetsJsonInput), "ISO-8859-9")); ArrayList userList = new ArrayList(); JSONParser jsonParser = new JSONParser(); JSONArray jsonArray = (JSONArray) jsonParser.parse(inputTW); int sayac = 0; for (Object obj : jsonArray) { JSONObject tweet = (JSONObject) obj; JSONObject user = (JSONObject) tweet.get("user"); // String userID = user.get("id").toString(); // String userName = user.get("name").toString(); String userID = user.get("id").toString(); String userName = user.get("name").toString(); if (userList.contains(userID) == false) { userList.add(userID);//from w w w . ja v a 2 s . co m bw.write(userID + "," + userName); bw.newLine(); sayac++; } } System.out.println(sayac); }
From source file:com.emc.ecs.sync.storage.CasStorageTest.java
@Test public void testDeleteClipList() throws Exception { int numClips = 100, maxBlobSize = 512000; FPPool pool = new FPPool(connectString1); try {//from ww w . java 2 s . c om // get clip count before test int originalClipCount = query(pool).size(); // create random data StringWriter sourceSummary = new StringWriter(); List<String> clipIds = createTestClips(pool, maxBlobSize, numClips, sourceSummary); // verify test clips were created Assert.assertEquals("wrong test clip count", originalClipCount + numClips, query(pool).size()); // write clip ID file File clipFile = File.createTempFile("clip", "lst"); clipFile.deleteOnExit(); BufferedWriter writer = new BufferedWriter(new FileWriter(clipFile)); for (String clipId : clipIds) { writer.write(clipId); writer.newLine(); } writer.close(); // construct EcsSync instance SyncConfig syncConfig = new SyncConfig(); syncConfig.setOptions(new SyncOptions().withThreadCount(CAS_THREADS) .withSourceListFile(clipFile.getAbsolutePath()).withDeleteSource(true)); syncConfig.setSource(new CasConfig().withConnectionString(connectString1)); syncConfig.setTarget(new com.emc.ecs.sync.config.storage.TestConfig()); EcsSync sync = new EcsSync(); sync.setSyncConfig(syncConfig); // run EcsSync sync.run(); System.out.println(sync.getStats().getStatsString()); // verify test clips were deleted int afterDeleteCount = query(pool).size(); if (originalClipCount != afterDeleteCount) { delete(pool, clipIds); Assert.fail("test clips not fully deleted"); } } finally { try { pool.Close(); } catch (Throwable t) { log.warn("failed to close pool", t); } } }
From source file:com.eviware.soapui.impl.wsdl.WsdlProject.java
private static void normalizeLineBreak(File target, File tmpFile) throws IOException { FileReader fr = new FileReader(tmpFile); BufferedReader in = new BufferedReader(fr); FileWriter fw = new FileWriter(target); BufferedWriter out = new BufferedWriter(fw); String line = ""; while ((line = in.readLine()) != null) { out.write(line);//from w ww .j a va 2s . c o m out.newLine(); out.flush(); } out.close(); fw.close(); in.close(); fr.close(); }
From source file:fastcall.FastCallSNP.java
private void callSNPByChromosomeTest(int currentChr, String vcfDirS, String referenceFileS, String chrSeq, int startPos, int endPos, int binSize) { int regionStart = startPos; int regionEnd = endPos; String outfileS = "chr" + FStringUtils.getNDigitNumber(3, currentChr) + ".VCF.txt"; outfileS = new File(vcfDirS, outfileS).getAbsolutePath(); int[][] binBound = this.creatBins(currentChr, binSize, regionStart, regionEnd); try {//w w w. ja va 2 s . c om HashMap<String, BufferedReader> bamPathPileupReaderMap = this.getBamPathPileupReaderMap(); ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap = this .getReaderRemainderMap(bamPathPileupReaderMap); BufferedWriter bw = IoUtils.getTextWriter(outfileS); bw.write(this.getAnnotation(referenceFileS)); bw.write(this.getVCFHeader()); bw.newLine(); for (int i = 0; i < binBound.length; i++) { long startTimePoint = System.nanoTime(); int binStart = binBound[i][0]; int binEnd = binBound[i][1]; ConcurrentHashMap<String, List<List<String>>> bamPileupResultMap = this.getBamPileupResultMap( currentChr, binStart, binEnd, bamPathPileupReaderMap, readerRemainderMap); StringBuilder[][] baseSb = this.getPopulateBaseBuilder(binStart, binEnd); int[][] depth = this.getPopulatedDepthArray(binStart, binEnd); this.fillDepthAndBase(bamPileupResultMap, baseSb, depth, binStart); String[][] base = this.getBaseMatrix(baseSb); ArrayList<Integer> positionList = this.getPositionList(binStart, binEnd); ConcurrentHashMap<Integer, String> posVCFMap = new ConcurrentHashMap( (int) ((binEnd - binStart + 1) * 1.5)); this.calculateVCF(posVCFMap, positionList, currentChr, binStart, chrSeq, depth, base); for (int j = 0; j < positionList.size(); j++) { String vcfStr = posVCFMap.get(positionList.get(j)); if (vcfStr == null) continue; bw.write(vcfStr); bw.newLine(); } StringBuilder sb = new StringBuilder(); sb.append("Bin from ").append(binStart).append(" to ").append(binEnd).append(" is finished. Took ") .append(Benchmark.getTimeSpanSeconds(startTimePoint)).append(" seconds. Memory used: ") .append(Benchmark.getUsedMemoryGb()).append(" Gb"); System.out.println(sb.toString()); } bw.flush(); bw.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println( "Chromosome " + String.valueOf(currentChr) + " is finished. File written to " + outfileS + "\n"); }