List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:org.crazydog.util.spring.StreamUtils.java
/** * Copy the contents of the given String to the given output OutputStream. * Leaves the stream open when done./*from w w w . ja v a2 s. com*/ * @param in the String to copy from * @param charset the Charset * @param out the OutputStream to copy to * @throws IOException in case of I/O errors */ public static void copy(String in, Charset charset, OutputStream out) throws IOException { org.springframework.util.Assert.notNull(in, "No input String specified"); org.springframework.util.Assert.notNull(charset, "No charset specified"); org.springframework.util.Assert.notNull(out, "No OutputStream specified"); Writer writer = new OutputStreamWriter(out, charset); writer.write(in); writer.flush(); }
From source file:com.tomgibara.cluster.CreateGaussianCross.java
private static void writeCluster(NormalizedRandomGenerator gen, double[] means, double[] deviations, int size, Writer writer) throws IOException { UncorrelatedRandomVectorGenerator c = new UncorrelatedRandomVectorGenerator(means, deviations, gen); for (int i = 0; i < size; i++) { double[] pt = c.nextVector(); writer.write(String.format("%3.3f %3.3f%n", pt[0], pt[1])); }/* w ww. j ava 2 s .c o m*/ }
From source file:Main.java
/** * Writes out the contents.//from w ww .j a va 2s. c om * @param outFile outFile * @param contents contents * @throws FileNotFoundException FileNotFoundException * @throws IOException IOException */ public static void setContents(final File outFile, final String contents) throws FileNotFoundException, IOException { if (outFile == null) { throw new IllegalArgumentException("File should not be null."); //$NON-NLS-1$ } if (outFile.exists()) { if (!outFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + outFile); //$NON-NLS-1$ } if (!outFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + outFile); //$NON-NLS-1$ } } Writer output = null; try { output = new BufferedWriter(new FileWriter(outFile)); if (contents != null) { output.write(contents); output.flush(); } } finally { if (output != null) { output.close(); } } }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
private static void saveKeyValues(Writer writer, HashMap settings) throws IOException { writer.write(" <settings>\n"); for (Iterator iterator = settings.entrySet().iterator(); iterator.hasNext();) { Entry entry = (Entry) iterator.next(); writer.write(" <entry"); writer.write(" key=\"" + entry.getKey() + "\""); writer.write(" value=\"" + entry.getValue() + "\"/>\n"); }//from w ww.j ava 2 s . co m writer.write(" </settings>\n"); }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
public static void saveSettings(IJCCTraySettings settings, Writer writer) throws IOException { try {//from w w w. j ava2s . c om writer.write("<?xml version='1.0' ?>\n"); writer.write("<cctraysettings>\n"); saveHosts(writer, settings.getHosts()); saveKeyValues(writer, settings.getSettings()); writer.write("</cctraysettings>\n"); } catch (IOException e) { throw e; } finally { writer.close(); } }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
private static void saveProjects(Writer writer, Collection projects) throws IOException { writer.write(" <projects>\n"); for (Iterator iterator2 = projects.iterator(); iterator2.hasNext();) { DashBoardProject project = (DashBoardProject) iterator2.next(); writer.write(" <project"); writer.write(" enabled=\"" + project.isEnabled() + "\""); writer.write(" name=\"" + project.getName() + "\""); writer.write("/>\n"); }// w w w . ja v a 2 s . c om writer.write(" </projects>\n"); }
From source file:edu.cornell.med.icb.io.TestResourceFinder.java
/** * Make the temp file outside of existing directory. * @throws IOException error making file *//*from w w w .j ava 2s . c o m*/ private static void makeTmpFile() throws IOException { final File tmpFile = new File("/tmp/temp-file.txt"); Writer output = null; try { output = new BufferedWriter(new FileWriter(tmpFile)); output.write("blah"); } finally { IOUtils.closeQuietly(output); } }
From source file:jp.igapyon.diary.v3.util.IgapyonV3Util.java
public static void writePostHtml(final Writer writer) throws IOException { writer.write("\n</div><!-- container-fluid -->\n"); writer.write("<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->\n"); writer.write(//from w w w.ja v a2 s . com "<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\n"); writer.write("<!-- Compiled and minified JavaScript -->\n"); writer.write( "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\"></script>\n"); if (false) { // Codes for direct jQuery call. writer.write("<script>\n"); writer.write("$(function() {\n"); // writer.write(" $(\"h2\").addClass(\"alert alert-warning\");\n"); // writer.write(" $(\"h3\").addClass(\"bg-success\");\n"); // writer.write(" $(\"h4\").addClass(\"bg-info\");\n"); // writer.write(" $(\"table\").addClass(\"table table-bordered\");\n"); writer.write("});\n"); writer.write("</script>\n"); } writer.write("</body>\n"); writer.write("</html>"); }
From source file:net.sourceforge.jcctray.utils.ObjectPersister.java
private static void saveHosts(Writer writer, Collection hosts) throws IOException { writer.write(" <hosts>\n"); for (Iterator iterator = hosts.iterator(); iterator.hasNext();) { Host host = (Host) iterator.next(); writer.write(" <host"); writer.write(" cruiseClass=\"" + escape(host.getCruiseClass()) + "\""); writer.write(" hostName=\"" + escape(host.getHostName()) + "\""); writer.write(" hostString=\"" + escape(host.getHostString()) + "\""); if (!StringUtils.isEmptyOrNull(host.getUsername())) { writer.write(" username=\"" + escape(host.getUsername()) + "\""); }// w w w . j a va 2s.c o m if (!StringUtils.isEmptyOrNull(host.getPassword())) { writer.write(" password=\"" + escape(host.getPassword()) + "\""); } writer.write(">\n"); saveProjects(writer, host.getConfiguredProjects()); writer.write(" </host>\n"); } writer.write(" </hosts>\n"); }
From source file:me.timothy.ddd.DDDUtils.java
public static void writeJSONPretty(Writer out, Collection<?> c, int indentation) throws IOException { out.write('['); indentation++;/* w ww . j a va 2s . c om*/ boolean first = true; for (Object o : c) { if (!first) out.write(','); else first = false; out.write('\n'); writeIndentation(out, indentation); write(out, o, indentation); } indentation--; out.write('\n'); writeIndentation(out, indentation); out.write(']'); }