List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:net.stuxcrystal.simpledev.configuration.parser.generators.xml.CommentAwareDumper.java
/** * Dumps a comment./*from ww w. ja v a 2s . c o m*/ * * @param writer The writer to write the comment into. * @param node The node that should be used. * @param indent The indent of the nodes. * @throws java.io.IOException If an I/O-Operation fails. */ private void dumpComment(BufferedWriter writer, Node<?> node, int indent) throws IOException { String[] comment = node.getComments(); for (String line : comment) { this.writeIndent(writer, indent); if (!(line == null || line.isEmpty())) { writer.write("<!-- "); writer.write(line); writer.write(" -->"); } writer.newLine(); } }
From source file:com.trackplus.ddl.DataReader.java
private static int getBlobTableData(BufferedWriter writer, Connection connection) throws DDLException { try {//from w ww . ja va2s .c om Statement st = connection.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM TBLOB"); int idx = 0; while (rs.next()) { StringBuilder line = new StringBuilder(); //OBJECTID String value = rs.getString("OBJECTID"); line.append(value).append(","); //BLOBVALUE Blob blobValue = rs.getBlob("BLOBVALUE"); if (blobValue != null) { String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); if (str.length() == 0) { str = " "; } line.append(str); } else { line.append("null"); } line.append(","); //TPUUID value = rs.getString("TPUUID"); line.append(value); writer.write(line.toString()); writer.newLine(); idx++; } rs.close(); return idx; } catch (SQLException ex) { throw new DDLException(ex.getMessage(), ex); } catch (IOException ex) { throw new DDLException(ex.getMessage(), ex); } }
From source file:de.syss.MifareClassicTool.Common.java
/** * Write an array of strings (each field is one line) to a given file. * @param file The file to write to./*from ww w . java2s.c o m*/ * @param lines The lines to save. * @param append Append to file (instead of replacing its content). * @return True if file writing was successful. False otherwise. */ public static boolean saveFile(File file, String[] lines, boolean append) { boolean noError = true; if (file != null && lines != null && isExternalStorageMounted()) { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file, append)); // Add new line before appending. if (append) { bw.newLine(); } int i; for (i = 0; i < lines.length - 1; i++) { bw.write(lines[i]); bw.newLine(); } bw.write(lines[i]); } catch (IOException e) { Log.e(LOG_TAG, "Error while writing to '" + file.getName() + "' file.", e); noError = false; } finally { if (bw != null) { try { bw.close(); } catch (IOException e) { Log.e(LOG_TAG, "Error while closing file.", e); noError = false; } } } } else { noError = false; } return noError; }
From source file:com.cloudera.kitten.lua.AsapLuaContainerLaunchParameters.java
private String writeExecutionScript(List<String> cmds) throws IOException { UUID id = UUID.randomUUID(); String ret = "script_" + id + ".sh"; File fout = new File("/tmp/" + ret); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); bw.write("#!/bin/bash"); bw.newLine(); for (String c : cmds) { bw.write(c);//from ww w.j a va 2 s . c o m bw.newLine(); } bw.close(); fout.setExecutable(true); return ret; }
From source file:com.cloudera.sqoop.manager.DirectPostgresqlManager.java
/** Write the COPY command to a temp file. * @return the filename we wrote to./*w ww .j a v a 2s. c om*/ */ private String writeCopyCommand(String command) throws IOException { String tmpDir = options.getTempDir(); File tempFile = File.createTempFile("tmp-", ".sql", new File(tmpDir)); BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile))); w.write(command); w.newLine(); w.close(); return tempFile.toString(); }
From source file:edu.uci.ics.jung.io.PajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may * be supplied by <code>vs</code> (defaults to no labels if null), * edge weights may be specified by <code>nev</code> * (defaults to weights of 1.0 if null), * and vertex locations may be specified by <code>vld</code> (defaults * to no locations if null). //from w ww . jav a 2 s . co m */ public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; writer.write("*Vertices " + graph.getVertexCount()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) writer.write(" \"" + label + "\""); } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) writer.write(" " + location.getX() + " " + location.getY() + " 0.0"); } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) d_set.addAll(graph.getEdges()); if (undirected) u_set.addAll(graph.getEdges()); if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }
From source file:io.hops.transaction.context.TransactionsStats.java
private EntityContextStat.StatsAggregator dump(BufferedWriter writer, TransactionStat transactionStat) throws IOException { if (transactionStat.ignoredException != null) { writer.write(transactionStat.ignoredException.toString()); writer.newLine(); writer.newLine();// w ww . j a v a2 s.c o m } EntityContextStat.StatsAggregator txAggStat = new EntityContextStat.StatsAggregator(); for (EntityContextStat contextStat : transactionStat.stats) { writer.write(contextStat.toString()); txAggStat.update(contextStat.getStatsAggregator()); } writer.write(txAggStat.toCSFString("Tx.")); writer.newLine(); return txAggStat; }
From source file:de.micromata.genome.util.runtime.config.LocalSettingsWriter.java
protected void writeEntryKeyValue(BufferedWriter writer, String key, String value) throws IOException { String enkey = PropertiesReadWriter.saveConvert(key, true, true, true); String envalue;//w w w. j av a 2s . c o m if (value == null) { envalue = ""; } else { envalue = PropertiesReadWriter.saveConvert(value, false, true, false); } writer.write(enkey + "=" + envalue); writer.newLine(); }
From source file:CSVWriter.java
/** * Writes a table model to csv formatted file * //from w w w . j a v a 2 s .c om * @param file * file to create * @param model * model to write * @throws IOException */ public void write(File file, CSVTableModel model, char separator) throws IOException { /* create file */ FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); String value; /* write columns */ if (model.areColumnsVisible()) { for (int column = 0; column < model.getColumnCount(); column++) { value = encodeValue(model.getColumnName(column), separator); bw.write(value); if (column < model.getColumnCount() - 1) { bw.write(separator); } else { bw.newLine(); } } } /* write data */ for (int row = 0; row < model.getRowCount(); row++) { for (int column = 0; column < model.getColumnCount(); column++) { value = encodeValue(model.getValueAt(row, column), separator); bw.write(value); if (column < model.getColumnCount() - 1) { bw.write(separator); } else { bw.newLine(); } } } /* close file */ bw.close(); }
From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may * be supplied by <code>vs</code> (defaults to no labels if null), * edge weights may be specified by <code>nev</code> * (defaults to weights of 1.0 if null), * and vertex locations may be specified by <code>vld</code> (defaults * to no locations if null). //from ww w . j a v a2 s. c om */ @SuppressWarnings("unchecked") public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; writer.write("*Vertices " + graph.getVertexCount()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) writer.write(" \"" + label + "\""); } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) writer.write(" " + location.getX() + " " + location.getY()); } if (shape != null) { writer.write(" " + shape.transform(currentVertex) + " x_fact 1"); } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) d_set.addAll(graph.getEdges()); if (undirected) u_set.addAll(graph.getEdges()); if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }