List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:com.hazelcast.stabilizer.Utils.java
public static void writeText(String text, File file) { if (text == null) { throw new NullPointerException("text can't be null"); }// ww w . j av a 2s . c o m if (file == null) { throw new NullPointerException("file can't be null"); } try { FileOutputStream stream = new FileOutputStream(file); try { Writer writer = new BufferedWriter(new OutputStreamWriter(stream)); writer.write(text); writer.close(); } finally { closeQuietly(stream); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.hazelcast.stabilizer.Utils.java
public static void appendText(String text, File file) { if (text == null) { throw new NullPointerException("text can't be null"); }//from w w w. j a v a2 s.c om if (file == null) { throw new NullPointerException("file can't be null"); } try { FileOutputStream stream = new FileOutputStream(file, true); try { Writer writer = new BufferedWriter(new OutputStreamWriter(stream)); writer.write(text); writer.close(); } finally { closeQuietly(stream); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.iisys.schub.processMining.similarity.AlgoController.java
public static void saveToOutputFile(String output, String outputFileName) { Writer out; try {//from ww w . ja v a 2 s .co m out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFileName), "UTF-8")); try { out.write(output); System.out .println("PROCESSMINING: Successfully saved smiliarity results to " + outputFileName + "!"); } finally { out.close(); out = null; } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Writes chars from a <code>StringBuffer</code> to a <code>Writer</code>. * /* w ww. j a v a 2 s. co m*/ * @param data the <code>StringBuffer</code> to write, null ignored * @param output the <code>Writer</code> to write to * @throws NullPointerException if output is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 * @deprecated replaced by write(CharSequence, Writer) */ @Deprecated public static void write(StringBuffer data, Writer output) throws IOException { if (data != null) { output.write(data.toString()); } }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * Write data from matrix out to specified file with each row on a separate line * * @param filename/*from w ww . j a va 2s.c o m*/ * @param realMatrix */ public static void saveMatrixText(String filename, RealMatrix realMatrix) { Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8")); double[][] matrix = realMatrix.getData(); for (double[] row : matrix) { writer.write(Arrays.toString(row) + "\n"); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:edu.cornell.med.icb.goby.modes.CompactToFastaMode.java
public static void writeSequence(final Writer writer, final MutableString sequence, final int fastaLineLength) throws IOException { final int length = sequence.length(); for (int i = 0; i < length; i++) { if (i != 0 && (i % fastaLineLength == 0)) { writer.write('\n'); }/*from w ww . j a v a 2 s. co m*/ writer.write(sequence.charAt(i)); } writer.write('\n'); }
From source file:de.iteratec.iteraplan.presentation.tags.StringEscapeUtilsFunction.java
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote, boolean escapeForwardSlash) throws IOException { if (out == null) { throw new IllegalArgumentException("The Writer must not be null"); }/*ww w. j a v a 2 s . co m*/ if (str == null) { return; } int sz; sz = str.length(); for (int i = 0; i < sz; i++) { char ch = str.charAt(i); // handle unicode if (ch > 0x7f) { out.write(ch); //these characters will not cause any harm, must not be escaped } else if (ch < 32) { switch (ch) { case '\b': out.write('\\'); out.write('b'); break; case '\n': out.write('\\'); out.write('n'); break; case '\t': out.write('\\'); out.write('t'); break; case '\f': out.write('\\'); out.write('f'); break; case '\r': out.write('\\'); out.write('r'); break; default: //controll characters should be escaped if (ch > 0xf) { out.write("\\u00" + hex(ch)); } else { out.write("\\u000" + hex(ch)); } break; } } else { switch (ch) { case '\'': if (escapeSingleQuote) { out.write('\\'); } out.write('\''); break; case '"': out.write('\\'); out.write('"'); break; case '\\': out.write('\\'); out.write('\\'); break; case '/': if (escapeForwardSlash) { out.write('\\'); } out.write('/'); break; default: out.write(ch); break; } } } }
From source file:net.sf.jasperreports.engine.export.JsonExporter.java
public static void writeBookmarks(List<PrintBookmark> bookmarks, Writer writer, JacksonUtil jacksonUtil) throws IOException { // exclude the methods marked with @JsonIgnore in PrintBookmarkMixin from PrintBookmark implementation jacksonUtil.getObjectMapper().addMixInAnnotations(PrintBookmark.class, PrintBookmarkMixin.class); writer.write("{"); writer.write("\"id\": \"bkmrk_" + (bookmarks.hashCode() & 0x7FFFFFFF) + "\","); writer.write("\"type\": \"bookmarks\","); writer.write("\"bookmarks\": " + jacksonUtil.getJsonString(bookmarks)); writer.write("}"); }
From source file:net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.java
/** * *///from w w w . j a v a 2s. co m public static void writeFontExtensionsProperties(String fontRegistryFactoryPropertyName, String fontRegistryFactoryPropertyValue, String fontFamiliesPropertyName, String fontFamiliesPropertyValue, OutputStream outputStream) throws JRException { Writer out = null; try { out = new OutputStreamWriter(outputStream, DEFAULT_ENCODING); out.write(fontRegistryFactoryPropertyName + "=" + fontRegistryFactoryPropertyValue + "\n"); out.write(fontFamiliesPropertyName + "=" + fontFamiliesPropertyValue + "\n"); out.flush(); } catch (Exception e) { throw new JRException(EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITER_ERROR, null, e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } }
From source file:DecorateMutationsSNP.java
/** * The procedure creates a .txt file containing the information about the SNP mutations in the extant units * The first row represents the position of each mutation that is a double value in the interval (0,1) * The other rows represent the leave nodes as a matrix of 0 and 1 indicating the absence/presence of the corresponding mutation * @param wholePath path of the directory where the output file is stored * @param arg instance of the class PopulationARG that represents the ARG of a single population (in this case and actual population) * @see PopulationARG// w w w . jav a 2 s.c o m */ public static void createSNP_TxtFile(String wholePath, PopulationARG arg) { Writer writer = null; File file = new File("" + wholePath); try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8")); TreeSet<Double> posMutations = GenerateAdmixturePopulations.getAllMutations(); //System.out.println("Creating file SNPs for population "+arg.getId_pop()); //System.out.println("# of all mutations in all populations "+posMutations.size()); writer.write("Population " + arg.getId_pop() + "\n"); writer.write("Number of extant units (rows): " + arg.getExtantUnits() + "\n"); writer.write("Number of SNPs for each extant unit (columns): " + posMutations.size() + "\n\n"); Iterator<Double> it_posMuts = posMutations.iterator(); Double position; while (it_posMuts.hasNext()) { position = it_posMuts.next(); String troncato = String.format("%.4f", position); writer.write(troncato + " "); } writer.write("\n\n"); //For each leave print a row representing the absence or presence of SNP mutations for (int i = 0; i < arg.getExtantUnits(); i++) { it_posMuts = posMutations.iterator(); while (it_posMuts.hasNext()) { position = it_posMuts.next(); //check if the arg has the mutation if (arg.getMutationSet().containsKey(position)) { //if yes then check if the leaf has the mutation //Mutation mut = arg.getMutationSet().get(position); TreeSet<Double> muts_set = arg.getNodeSet().get(i).getMutation_set(); if (muts_set.contains(position)) writer.write("1 "); else writer.write("0 "); } else writer.write("0 "); } writer.write("\n"); } writer.close(); } //fine try catch (IOException ex) { // report } }