List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:edu.ucsd.crbs.cws.io.ResourceToExecutableScriptWriterImpl.java
/** * Writes a given resource to an executable script file. The result is written to * <b>destinationScript</b> and this script is made executable via File setExecutable * method.//from w w w. j ava2 s . c o m * * @param resourcePath Path that can be loaded via {@link Class.class.getResourceAsStream} * @param destinationScript File to write script to * @param replacer Optional object that lets caller alter script on a line by line basis before it is written * @throws Exception if there is an io error * @throws IllegalArgumentException if either <b>resourcePath</b> or <b>destinationScript</b> are null */ @Override public void writeResourceToScript(final String resourcePath, final String destinationScript, StringReplacer replacer) throws Exception { if (resourcePath == null) { throw new IllegalArgumentException("resourcePath method parameter cannot be null"); } if (destinationScript == null) { throw new IllegalArgumentException("destinationScript method parameter cannot be null"); } //load script List<String> scriptLines = IOUtils.readLines(Class.class.getResourceAsStream(resourcePath)); BufferedWriter bw = new BufferedWriter(new FileWriter(destinationScript)); for (String line : scriptLines) { if (replacer != null) { bw.write(replacer.replace(line)); } else { bw.write(line); } bw.newLine(); } bw.flush(); bw.close(); //make script executable File script = new File(destinationScript); script.setExecutable(true, false); }
From source file:fr.itinerennes.onebusaway.bundle.tasks.GenerateRoutesCsvTask.java
/** * {@inheritDoc}/*from ww w . ja v a2s . c o m*/ * * @see java.lang.Runnable#run() */ @Override public void run() { BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), CHARSET)); // output routes count out.write(String.valueOf(gtfsDao.getAllRoutes().size())); out.newLine(); for (final Route route : gtfsDao.getAllRoutes()) { out.write(route.getId().toString()); out.write(';'); out.write(route.getShortName()); out.write(';'); out.write(route.getLongName()); out.write(';'); out.write(route.getTextColor()); out.write(';'); out.write(route.getColor()); out.write(';'); out.newLine(); } } catch (final FileNotFoundException e) { LOGGER.error("output file not found", e); } catch (final IOException e) { LOGGER.error("can't write to output file", e); } finally { IOUtils.closeQuietly(out); } }
From source file:com.ibm.dbwkl.request.internal.SetupHandler.java
/** * @param configFile//from ww w .j a va2 s. c o m * @return returns the result after writing the new setup file */ private STAFResult WriteAutoSetup(File configFile) { // Open the file and add the options try { FileWriter writer = new FileWriter(configFile, true); BufferedWriter bw = new BufferedWriter(writer); String jcclibs = this.parseResult.get(Options.SETUP_JCCLIBS); bw.newLine(); bw.write("# [DB2WKL SETUP] (Don't remove the comments!)\n"); bw.write("# DB2 Workload Service\n"); bw.write("# (this section was generated by the setup command)" + "\n"); bw.write("SET SYSTEM VAR IBM/DB2WKL/AutoSetup=true" + "\n"); if (this.parseResult.containsKey(Options.SETUP_JCCLIBS)) { bw.write("SET SYSTEM VAR IBM/OMPE/DB2WKL/JCCLIB=\"" + FilenameUtils.separatorsToUnix(jcclibs) + "\"" + "\n"); STAFHandler.instance.getSTAFHandle().submit2("local", "VAR", "SET SYSTEM VAR IBM/OMPE/DB2WKL/JCCLIB=\"" + FilenameUtils.separatorsToUnix(jcclibs) + "\""); } else { bw.write( "SET SYSTEM VAR IBM/OMPE/DB2WKL/JCCLIB=\"{STAF/config/STAFroot}/services/db2wkl/libs/jcc/\"" + "\n"); STAFHandler.instance.getSTAFHandle().submit2("local", "VAR", "SET SYSTEM VAR IBM/OMPE/DB2WKL/JCCLIB=\"{STAF/config/STAFroot}/services/db2wkl/libs/jcc/\""); } bw.write( "SERVICE db2wkl LIBRARY JSTAF EXECUTE {STAF/config/STAFroot}/services/db2wkl/db2wkl.jar OPTION JVMName=DB2WKLJVM" + "\n"); bw.write("# [DB2WKL SETUP]\n"); bw.newLine(); bw.close(); writer.close(); // when writing the file was successful also register the variables to be available immedately STAFHandler.instance.getSTAFHandle().submit2("local", "VAR", "SET SYSTEM VAR IBM/DB2WKL/AutoSetup=true"); } catch (IOException e) { Logger.log("Could not write into config file: " + e.getMessage(), LogLevel.Error); return new STAFResult(STAFResult.FileWriteError); } return new STAFResult(STAFResult.Ok); }
From source file:de.clusteval.data.dataset.generator.CassiniDataSetGenerator.java
@Override protected GoldStandard generateGoldStandard() throws GoldStandardGenerationException { try {//from ww w. j a v a2 s . c o m // goldstandard file File goldStandardFile = new File(FileUtils.buildPath(this.repository.getBasePath(GoldStandard.class), this.getFolderName(), this.getFileName())); BufferedWriter writer = new BufferedWriter(new FileWriter(goldStandardFile)); for (int row = 0; row < classes.length; row++) { writer.append((row + 1) + "\t" + classes[row] + ":1.0"); writer.newLine(); } writer.close(); return new GoldStandard(repository, goldStandardFile.lastModified(), goldStandardFile); } catch (IOException e) { e.printStackTrace(); } catch (RegisterException e) { e.printStackTrace(); } throw new GoldStandardGenerationException("The goldstandard could not be generated!"); }
From source file:com.codecrate.webstart.GenerateJnlpMojo.java
private void addLine(BufferedWriter writer, String string) throws IOException { writer.append(string); writer.newLine(); }
From source file:com.codemage.sql.util.SonarQubeManager.java
public void createJavaFile(String JavaCode) { BufferedWriter bw = null; try {//from w w w . j a v a 2 s . c om // APPEND MODE SET HERE bw = new BufferedWriter(new FileWriter( "E:\\Smile24\\Projects\\0005 - CAL\\sampleAnalyseCode\\src\\main\\java\\checkbook.java", false)); bw.write(JavaCode); bw.newLine(); bw.flush(); } catch (IOException ioe) { } finally { // always close the file if (bw != null) { try { bw.close(); } catch (IOException ioe2) { // just ignore it } } } // end try/catch/finally }
From source file:playground.johannes.snowball.Histogram.java
public void dumpRawData(String filename) throws IOException { fillBins();/* w w w . j a v a2 s . c o m*/ double min, max, width; if (bounds != null) { min = bounds[0]; max = bounds[1]; } else { double minmax[] = getMinMax(); min = minmax[0]; max = minmax[1]; } if (binWidth > 0) { width = binWidth; } else { width = (max - min) / (double) bincount; } BufferedWriter writer = IOUtils.getBufferedWriter(filename); writer.write("bin\tvalue"); writer.newLine(); int cnt = bins.size(); for (int i = 0; i < cnt; i++) { writer.write(String.format(Locale.US, "%1$s\t%2$s", i * width + min, bins.get(i))); writer.newLine(); } writer.close(); }
From source file:org.lieuofs.extraction.etatpays.ExtractionGeTaX.java
public void extraire() throws IOException { EtatCritere critere = new EtatCritere(); Calendar cal = Calendar.getInstance(); cal.set(2012, Calendar.DECEMBER, 31); critere.setReconnuSuisseALaDate(cal.getTime()); Set<IEtat> etats = gestionnaire.rechercher(critere); List<IEtat> listeEtat = new ArrayList<IEtat>(etats); Collections.sort(listeEtat, new Comparator<IEtat>() { @Override/*from ww w .jav a2 s .com*/ public int compare(IEtat o1, IEtat o2) { return o1.getNumeroOFS() - o2.getNumeroOFS(); } }); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("ExtractionEtatGETaX2012.csv")), Charset.forName("ISO8859-1"))); for (IEtat etat : listeEtat) { writer.write(String.valueOf(etat.getNumeroOFS())); writer.write(";"); writer.write(etat.getFormeCourte("fr")); writer.newLine(); } writer.close(); }
From source file:com.zack6849.superlogger.Main.java
public void log(String line, LoggingCategory category) { BufferedWriter writer = getFile(category).getWriter(); try {/*from www . ja v a2s . c om*/ writer.write(getTime() + line); writer.newLine(); writer.flush(); } catch (IOException e) { logger.severe("Error writing line to " + category.getFileName() + " for LoggingCategory." + category.toString()); e.printStackTrace(); } }
From source file:autonomouspathplanner.ftp.FTP.java
/** * Uploads a file to the server/*from www .j a v a 2 s. c o m*/ * @param locationToUpload the remote location on the server to upload the file * @param f the file on the computer to upload * @return true if operation completes successfully, false otherwise */ public boolean uploadToServer(String locationToUpload, File f) { try { if (client == null) { if (!connectToServer()) return false; } OutputStream s = client.storeFileStream(locationToUpload); BufferedWriter buff = new BufferedWriter(new OutputStreamWriter(s)); for (String str : FileIO.getAllLines(f)) { buff.write(str); buff.newLine(); } buff.close(); } catch (IOException ex) { Logger.getLogger(FTP.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (client.isConnected()) { client.logout(); client.disconnect(); client = null; } } catch (IOException ex) { ex.printStackTrace(); } } return true; }