List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:Main.java
public static BufferedWriter getWriter(File file, final String group, String comment) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(file)) { @Override/* w ww . ja va 2s. com*/ public void close() throws IOException { write("</" + group + ">"); super.close(); } }; bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); bw.newLine(); bw.newLine(); bw.write("<!--" + comment + "-->"); bw.newLine(); bw.newLine(); bw.write("<" + group + ">"); bw.newLine(); return bw; }
From source file:eu.cloud4soa.c4sgitservice.utils.Util.java
public static synchronized void appendToFile(String filename, String text) { FileWriter fWriter = null;/*from w ww.j a va2s. com*/ BufferedWriter writer = null; try { fWriter = new FileWriter(filename, true); writer = new BufferedWriter(fWriter); writer.append(text); writer.newLine(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void writeBucketTestRecord(BufferedWriter out, String label, int id, double parameter) throws Exception { out.write("20170101"); out.write("\t"); out.write(label);// ww w . ja v a 2s.com out.write("\t"); out.write(Integer.toString(id)); out.write("\t"); out.write(Double.toString(parameter)); out.newLine(); }
From source file:com.cemso.util.CheckDeviceStateExcuter.java
public static void checkWait() { if (log.isInfoEnabled()) { log.info("auto refresh is waiting..."); try {/*from w ww.j a v a2 s. c om*/ File f = new File("C:/DLLfunctionsTest.txt"); FileWriter fw = new FileWriter(f, true); BufferedWriter bw = new BufferedWriter(fw); bw.newLine(); bw.append(new java.util.Date().toString() + ": auto refresh is waiting..."); bw.newLine(); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } checkerHandle1.cancel(true); }
From source file:com.github.jmabuin.blaspark.io.IO.java
public static void writeVectorToFileInHDFS(String file, DenseVector vector, Configuration conf) { try {/*from w w w . j a va 2 s . c o m*/ FileSystem fs = FileSystem.get(conf); Path pt = new Path(file); //FileSystem fileSystem = FileSystem.get(context.getConfiguration()); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fs.create(pt, true))); bw.write("%%MatrixMarket matrix array real general"); bw.newLine(); bw.write(vector.size() + " 1"); bw.newLine(); for (int i = 0; i < vector.size(); i++) { bw.write(String.valueOf(vector.apply(i))); bw.newLine(); } bw.close(); //fs.close(); } catch (IOException e) { LOG.error("Error in " + IO.class.getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:com.cemso.util.CheckDeviceStateExcuter.java
public static void checkStart() { if (log.isDebugEnabled()) { log.debug("CheckDeviceStateExcuter.checkStart()..."); }/* w ww . j a va 2s . c om*/ CheckRunner checker = new CheckDeviceStateExcuter().new CheckRunner(); Thread t = new Thread(checker, "checker"); checkerThread = t; final ScheduledFuture<?> checkerHandle = scheduler.scheduleAtFixedRate(t, 1, 2, TimeUnit.MINUTES); checkerHandle1 = checkerHandle; if (log.isInfoEnabled()) { log.info("auto refresh is started..."); try { File f = new File("C:/DLLfunctionsTest.txt"); FileWriter fw = new FileWriter(f, true); BufferedWriter bw = new BufferedWriter(fw); bw.newLine(); bw.append(new java.util.Date().toString() + ": auto refresh is started..."); bw.newLine(); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:PipedCharacters.java
public static void writeStuff(Writer rawOut) { try {/*from w w w . ja v a 2s.c o m*/ BufferedWriter out = new BufferedWriter(rawOut); String[][] line = { { "Java", "Source", "and", "Support." } }; for (int i = 0; i < line.length; i++) { String[] word = line[i]; for (int j = 0; j < word.length; j++) { out.write(word[j]); } out.newLine(); } out.flush(); out.close(); } catch (IOException x) { x.printStackTrace(); } }
From source file:it.geosolutions.tools.io.file.writer.Writer.java
/** * Open 'destination' file in append mode and append content of the * 'toAppend' file//from ww w. j a v a 2s. c om * * @param toAppend * @param destination * @throws IOException */ public static void appendFile(File toAppend, File destination) throws IOException { FileWriter fw = null; BufferedWriter bw = null; LineIterator it = null; try { fw = new FileWriter(destination, true); bw = new BufferedWriter(fw); it = FileUtils.lineIterator(toAppend); while (it.hasNext()) { bw.append(it.nextLine()); bw.newLine(); } bw.flush(); } finally { if (it != null) { it.close(); } if (bw != null) { IOUtils.closeQuietly(bw); } if (fw != null) { IOUtils.closeQuietly(fw); } } }
From source file:com.calamp.services.kinesis.events.writer.CalAmpEventWriter.java
public static void genRandEventsToFile(String filePath, int numToGen) throws IOException { // Repeatedly send stock trades with a some milliseconds wait in between BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, false)); for (int i = 0; i < numToGen; i++) { CalAmpEvent event = CalAmpEventGenerator.getRandomMessage(); bw.write(event.toJsonAsString()); bw.newLine(); //System.out.println( event.toJsonAsString() ); //System.out.println( CalAmpEvent.fromJsonAsString(event.toJsonAsString()) ); }//w w w . jav a 2s . c o m if (bw != null) { bw.close(); } }
From source file:mase.MaseEvolve.java
public static Map<String, String> readParams(String[] args) throws Exception { // Reads command line parameters to a map // Checks the parent order Map<String, String> argsPars = new LinkedHashMap<>(); int parentOrder = 0; for (int i = 0; i < args.length; i++) { if (args[i].equals("-p")) { String par = args[i + 1]; String[] kv = par.split("="); if (kv[0].startsWith("parent")) { // Parent parameter if (kv[0].equals("parent")) { // Parent with no number argsPars.put("parent." + parentOrder, kv[1]); parentOrder++;//from w w w . j a va 2 s. co m } else { // Numbered parent String[] split = kv[0].split("\\."); int num = Integer.parseInt(split[1]); if (num != parentOrder) { throw new Exception("Parent out of order: " + par); } argsPars.put("parent." + num, kv[1]); parentOrder++; } } else { // Not a parent parameter argsPars.put(kv[0], kv[1]); } } else if (args[i].equals("-file")) { argsPars.put("parent.0", args[i + 1]); } } // Write command line parameters to a temp file -- the root file File tempFile = File.createTempFile("masetemp", ".params", new File(".")); BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile)); for (Entry<String, String> e : argsPars.entrySet()) { bw.write(e.getKey() + " = " + e.getValue()); bw.newLine(); } bw.close(); // Load all the parameter files Map<String, String> pars = new LinkedHashMap<>(); loadParams(pars, tempFile); tempFile.delete(); return pars; }