List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:org.apache.druid.query.aggregation.datasketches.hll.GenerateTestData.java
private static void writeRawRecord(BufferedWriter out, String date, String dimension, int id) throws Exception { out.write(date);/*from w w w.j a v a 2 s . c o m*/ out.write("\t"); out.write(dimension); out.write("\t"); out.write(Integer.toString(id)); out.newLine(); }
From source file:Main.java
/** * Write an object that is already base64 encoded. *//*from w ww.j av a2s . co m*/ public static void writeBase64Object(BufferedWriter bw, String type, String object) throws IOException { bw.write("-----BEGIN "); bw.write(type); bw.write("-----"); bw.newLine(); bw.write(object); char lastChar = object.charAt(object.length() - 1); if (('\n' != lastChar) && ('\r' != lastChar)) { bw.newLine(); } bw.write("-----END "); bw.write(type); bw.write("-----"); bw.newLine(); bw.flush(); }
From source file:com.xafero.vee.cmd.MainApp.java
private static void printVersion() throws IOException { StringWriter writer;/*from ww w . j a v a2 s .com*/ BufferedWriter out = new BufferedWriter(writer = new StringWriter()); out.write(APP_SHORT_NAME + " " + APP_VER + " built on JSR 223."); out.newLine(); out.newLine(); out.write("Copyright (C) 2015 xafero"); out.newLine(); out.write("License AGPLv3+: GNU AGPL version 3 or later"); out.newLine(); out.write("<https://gnu.org/licenses/agpl.html>."); out.newLine(); out.write("This is free software: you are free to change and redistribute it."); out.newLine(); out.write("There is NO WARRANTY, to the extent permitted by law."); out.newLine(); out.newLine(); out.write("Please send bug reports and questions to <" + APP_SRC_URL + ">."); out.newLine(); out.flush(); System.out.print(writer.toString()); }
From source file:com.thinkit.operationsys.util.FileUtil.java
public static void copyFile(String src, String dest) { System.out.println("copy"); File f1 = new File(src); File f2 = new File(dest); //int b=0;//from w w w . j a v a2 s . co m String line = ""; try { FileReader reader = new FileReader(f1); FileWriter writer = new FileWriter(f2); BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); while ((line = br.readLine()) != null) { System.out.println(line); bw.write(line); bw.newLine(); bw.flush(); } reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.stuxcrystal.simpledev.configuration.parser.generators.xml.CommentAwareDumper.java
/** * Dumps a node tree into a XML-File.//from ww w. ja v a 2s. c o m * * @param stream The stream to write data to. * @param node The node to dump. * @throws java.io.IOException If an I/O-Operation fils. */ public static void dump(OutputStream stream, Node<?> node) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); writer.write(XML_DOCTYPE); writer.newLine(); // Set the node name if necessary. if (node.getName() == null || node.getName().isEmpty()) node.setName("xml"); CommentAwareDumper.DUMPER.dumpNode(writer, node, 0); writer.close(); }
From source file:Main.java
public static boolean isRooted() { Process p;/*from ww w. ja v a 2 s . co m*/ try { p = new ProcessBuilder("su").start(); BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); stdin.write("whoami"); stdin.newLine(); stdin.write("exit"); stdin.newLine(); stdin.close(); try { p.waitFor(); if (!stdout.ready()) return false; String user = stdout.readLine(); //We only expect one line of output stdout.close(); if (user == "root") { return true; } else { return false; } } catch (InterruptedException e) { e.printStackTrace(); return false; } } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:org.apache.druid.query.aggregation.datasketches.hll.GenerateTestData.java
private static void writeSketchRecord(BufferedWriter out, String date, String dimension, HllSketch sketch) throws Exception { out.write(date);/*from w w w .j a v a 2 s.c om*/ out.write("\t"); out.write(dimension); out.write("\t"); out.write(Base64.encodeBase64String(sketch.toCompactByteArray())); out.newLine(); }
From source file:com.netflix.config.DynamicFileConfigurationTest.java
static File createConfigFile(String prefix) throws Exception { configFile = File.createTempFile(prefix, ".properties"); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(configFile), "UTF-8")); writer.write("dprops1=123456789"); writer.newLine(); writer.write("dprops2=79.98"); writer.newLine();/*from w ww . ja va2 s . com*/ writer.close(); System.err.println(configFile.getPath() + " created"); return configFile; }
From source file:org.apache.flink.streaming.util.TestDataUtil.java
public static void download(String fileName) { LOG.info("downloading " + fileName); try {//from ww w .j a v a2 s . c om URL website = new URL(testRepoUrl + fileName); BufferedReader bReader = new BufferedReader(new InputStreamReader(website.openStream())); File outFile = new File(testDataDir + fileName); BufferedWriter bWriter = new BufferedWriter(new FileWriter(outFile)); String line; while ((line = bReader.readLine()) != null) { bWriter.write(line); bWriter.newLine(); } bWriter.close(); } catch (MalformedURLException e) { throw new RuntimeException("URL is malformed: ", e); } catch (IOException e) { throw new RuntimeException("Unexpected problem while downloading file " + fileName, e); } }
From source file:Main.java
public static void appendLog(String text) { Log.d("LOGFILE", text); SimpleDateFormat sTime = new SimpleDateFormat("dd/MMM/yyyy - hh:mm:ss"); String timeFormat = sTime.format(new Date()); File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/Cura/Logs/"); dir.mkdirs();/*from w ww. ja va 2s. com*/ File logFile = new File(dir, "Cura_Logs_DEBUG.txt"); if (!logFile.exists()) { try { logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); if (text.compareTo("wipe") == 0) logFile.delete(); else { buf.append("[" + timeFormat + "] - "); buf.append(text); buf.newLine(); buf.close(); } } catch (IOException e) { e.printStackTrace(); } }