List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:com.healthmarketscience.jackcess.ExportUtil.java
private static void writeValue(BufferedWriter out, String value, char quote, Pattern needsQuotePattern) throws IOException { if (!needsQuotePattern.matcher(value).find()) { // no quotes necessary out.write(value); return;//from w ww .ja v a 2 s .c om } // wrap the value in quotes and handle internal quotes out.write(quote); for (int i = 0; i < value.length(); ++i) { char c = value.charAt(i); if (c == quote) { out.write(quote); } out.write(c); } out.write(quote); }
From source file:playground.johannes.socialnets.GraphStatistics.java
static public Histogram createDegreeHistogram(Graph g, int min, int max, int ignoreWave) { Set<Vertex> vertices = new HashSet<Vertex>(); for (Object o : g.getVertices()) { if (((Vertex) o).getUserDatum(UserDataKeys.ANONYMOUS_KEY) == null) vertices.add((Vertex) o);/*w ww . j a v a 2 s .co m*/ } DoubleArrayList values = new DoubleArrayList(vertices.size()); DoubleArrayList weights = new DoubleArrayList(vertices.size()); try { BufferedWriter writer = IOUtils.getBufferedWriter(outputDir + ignoreWave + ".weights.txt"); for (Vertex v : vertices) { int k = v.degree(); values.add(k); writer.write(String.valueOf(k)); writer.write("\t"); Integer wave = (Integer) v.getUserDatum(UserDataKeys.SAMPLED_KEY); double w = 1; if (wave == null || k == 0) weights.add(1); else { // w = 1 / (1 - Math.pow((1 - fracVertices),k)); w = 1;// / (Double)v.getUserDatum(UserDataKeys.SAMPLE_PROBA_KEY); weights.add(w); } writer.write(String.valueOf(w)); writer.newLine(); writer.flush(); } writer.close(); } catch (Exception e) { e.printStackTrace(); } if (min < 0 && max < 0) { DoubleArrayList copy = values.copy(); copy.sort(); min = (int) copy.get(0); max = (int) copy.get(values.size() - 1); } Histogram hist = new Histogram(1.0, 0, max); for (int i = 0; i < values.size(); i++) { hist.add(values.get(i), weights.get(i)); } System.out.println("Gamma exponent is estimated to " + estimatePowerLawExponent(values)); return hist; }
From source file:funcoes.funcoes.java
public static void geraLog(String nome, String log) { int dia, mes, ano; String data_log;/*from w w w . ja v a 2 s .c o m*/ Calendar data; data = Calendar.getInstance(); dia = data.get(Calendar.DAY_OF_MONTH); mes = data.get(Calendar.MONTH); ano = data.get(Calendar.YEAR); data_log = +dia + "_" + (mes + 1) + "_" + ano; if (dia < 10 && mes < 10) { data_log = "0" + dia + "_0" + (mes + 1) + "_" + ano; } else if (dia < 10 && mes >= 10) { data_log = "0" + dia + "_" + (mes + 1) + "_" + ano; } else if (dia >= 10 && mes < 10) { data_log = dia + "_0" + (mes + 1) + "_" + ano; } else { data_log = dia + "_" + (mes + 1) + "_" + ano; } File arquivo = new File("C:/SOVIONG/log/log_" + data_log + ".txt"); try { if (!arquivo.exists()) { //cria um arquivo (vazio) arquivo.createNewFile(); } //caso seja um diretrio, possvel listar seus arquivos e diretrios //File[] arquivos = arquivo.listFiles(); //escreve no arquivo FileWriter fw = new FileWriter(arquivo, true); BufferedWriter bw = new BufferedWriter(fw); bw.write(log + " " + data.getTime().toLocaleString().substring(10, data.getTime().toLocaleString().length()) + " do dia: " + data.getTime().toLocaleString().substring(0, 10)); bw.newLine(); bw.close(); fw.close(); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
From source file:edu.cmu.cs.lti.ark.fn.data.prep.ParsePreparation.java
private static void writeStuff(BufferedWriter bWriter, List<String> words, List<String> pos, List<String> parent, List<String> label) throws IOException { int size = words.size(); for (int i = 0; i < size; i++) { String line = ""; line += (i + 1) + "\t"; line += words.get(i).toLowerCase() + "\t"; line += words.get(i).toLowerCase() + "\t"; line += pos.get(i) + "\t"; line += pos.get(i) + "\t"; line += "_\t"; line += parent.get(i) + "\t"; line += label.get(i);/* w w w. ja va2 s.co m*/ bWriter.write(line + "\n"); } bWriter.write("\n"); }
From source file:com.iitb.cse.ConnectionInfo.java
public static void writeToMyLog(int expid, String macAdrress, String message) { String location = ""; if (!Constants.experimentDetailsDirectory.endsWith("/")) { location = Constants.experimentDetailsDirectory + "/"; }// w w w .j a v a2s. c o m location += Integer.toString(expid) + macAdrress + "_log.txt"; File file = new File(location); try { FileWriter fw = new FileWriter(file, true); BufferedWriter bw = new BufferedWriter(fw); Date date = new Date(); System.out.println(date); bw.write(date.toString() + " --> " + message + "\n"); bw.close(); } catch (IOException ex) { System.out.println("\nEXCEPTION [writeToMyLog]:" + ex.toString()); } }
From source file:com.liferay.util.FileUtil.java
public static void write(File file, String s) throws IOException { if (file.getParent() != null) { mkdirs(file.getParent());// w w w . j a va 2s.c om } BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.flush(); bw.write(s); bw.close(); }
From source file:net.naijatek.myalumni.util.utilities.FileUtil.java
/** * Write content to_email a fileName with the destEncoding * /*w w w .java 2s . com*/ * @param content String * @param fileName String * @param destEncoding String * @throws FileNotFoundException * @throws IOException */ public static void writeFile(final String content, final String fileName, final String destEncoding) throws FileNotFoundException, IOException { File file = null; try { file = new File(fileName); if (file.isFile() == false) { throw new IOException("'" + fileName + "' is not a file."); } if (file.canWrite() == false) { throw new IOException("'" + fileName + "' is a read-only file."); } } finally { // we dont have to close File here } BufferedWriter out = null; try { FileOutputStream fos = new FileOutputStream(fileName); out = new BufferedWriter(new OutputStreamWriter(fos, destEncoding)); out.write(content); out.flush(); } catch (FileNotFoundException fe) { logger.error("Error", fe); throw fe; } catch (IOException e) { logger.error("Error", e); throw e; } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { } } }
From source file:com.github.jsonj.tools.JsonSerializer.java
private static void serialize(final BufferedWriter bw, final JsonElement json, final boolean pretty, final int indent) throws IOException { if (json == null) { return;//from w w w. ja v a 2 s . c o m } JsonType type = json.type(); switch (type) { case object: bw.write('{'); newline(bw, indent + 1, pretty); Iterator<Entry<String, JsonElement>> iterator = json.asObject().entrySet().iterator(); while (iterator.hasNext()) { Entry<String, JsonElement> entry = iterator.next(); String key = entry.getKey(); JsonElement value = entry.getValue(); if (value != null) { bw.write('"'); bw.write(jsonEscape(key)); bw.write("\":"); serialize(bw, value, pretty, indent + 1); if (iterator.hasNext()) { bw.write(','); newline(bw, indent + 1, pretty); } } } newline(bw, indent, pretty); bw.write('}'); break; case array: bw.write('['); newline(bw, indent + 1, pretty); Iterator<JsonElement> arrayIterator = json.asArray().iterator(); while (arrayIterator.hasNext()) { JsonElement value = arrayIterator.next(); boolean nestedPretty = false; if (value.isObject()) { nestedPretty = true; } serialize(bw, value, nestedPretty, indent + 1); if (arrayIterator.hasNext()) { bw.write(','); newline(bw, indent + 1, nestedPretty); } } newline(bw, indent, pretty); bw.write(']'); break; case string: bw.write(json.toString()); break; case bool: bw.write(json.toString()); break; case number: bw.write(json.toString()); break; case nullValue: bw.write(json.toString()); break; default: throw new IllegalArgumentException("unhandled type " + type); } }
From source file:emperior.Main.java
public static void addLineToLogFile(String input) { if (!adminmode) { FileWriter fstream;// w ww.j av a 2s . c o m try { fstream = new FileWriter(logFile, true); BufferedWriter out = new BufferedWriter(fstream); out.write(getCurrentTime() + " {" + applicant + " | " + group + "}" + "<" + Main.tasktypes.get(Main.activeType) + "_" + Main.tasks.get(Main.activeTask) + "> " + input); out.newLine(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:entity.files.SYSFilesTools.java
public static File getHtmlFile(String html, String prefix, String ext) { File temp = null;//from ww w. j av a 2 s .co m try { // Create temp file. temp = File.createTempFile(prefix, ext); String text = "<html><head>"; text += OPDE.getCSS(); text += "</head><body>" + SYSTools.htmlUmlautConversion(html) + "<hr/>" + "<div id=\"fonttext\">" + "<b>" + SYSTools.xx("misc.msg.endofreport") + "</b><br/>" + (OPDE.getLogin() != null ? SYSTools.htmlUmlautConversion(OPDE.getLogin().getUser().getUID()) : "") + "<br/>" + DateFormat.getDateTimeInstance().format(new Date()) + "<br/>" + OPDE.getAppInfo().getProgname() + ", v" + OPDE.getAppInfo().getVersion() + "/" + OPDE.getAppInfo().getBuildnum() + "</div></body></html>"; // Write to temp file BufferedWriter out = new BufferedWriter(new FileWriter(temp)); out.write(text); out.close(); } catch (IOException e) { OPDE.error(e); } return temp; }