List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:com.cloudhopper.sxmp.SxmpWriter.java
static private void writeRequestResponseTag(Writer out, Operation operation) throws IOException { out.write(operation.getType().getValue()); if (operation.isRequest()) { out.write("Request"); } else {//from www . j av a 2 s. com out.write("Response"); } }
From source file:com.moss.appsnap.keeper.freedesktop.FreeDesktopAppHandler.java
private static void write(String text, File dest) throws IOException { Writer writer = new FileWriter(dest); writer.write(text); writer.close();//from ww w . j a v a 2s. c o m }
From source file:CopyUtils.java
/** * Copy chars from a <code>String</code> to a <code>Writer</code>. * @param input the <code>String</code> to read from * @param output the <code>Writer</code> to write to * @throws IOException In case of an I/O problem *//*from w ww . ja v a 2 s. c o m*/ public static void copy(String input, Writer output) throws IOException { output.write(input); }
From source file:com.spectralogic.ds3client.helpers.channels.WindowedSeekableByteChannel_Test.java
private static void writeToChannel(final String string, final SeekableByteChannel channel) throws IOException { final Writer writer = Channels.newWriter(channel, "UTF-8"); writer.write(string); writer.flush();/*w w w .j a v a2s . co m*/ }
From source file:com.cloudhopper.sxmp.SxmpWriter.java
static private void writeRequestResponseStartTag(Writer out, Operation operation) throws IOException { out.write(" <"); writeRequestResponseTag(out, operation); if (operation.getReferenceId() != null) { out.write(" referenceId=\""); out.write(operation.getReferenceId()); out.write("\""); }//w w w. j a va 2s. c om out.write(">\n"); }
From source file:com.day.cq.wcm.foundation.forms.LayoutHelper.java
/** * Print the left column, title and required. This method creates a wrapper * div with the class form_leftcol, inside the divs are two divs, the first * one containing the label with the class form_leftcollabel. The second * inner div contains a star if the field is required, the div has the class * form_leftcolmark./*from w w w .ja va2s.c o m*/ * <p/> * The <code>title</code> is encoded using * {@link StringEscapeUtils#escapeHtml4(String)} before it is written to * the {@link Writer}. * * @param fieldId The id of the field (not the name) - This can be null if * title is null. * @param title The title of the field (or null) * @param required Flag indicating if this field is required. * @param hideLabel Option to completely hide the label (removes form_leftcollabel and form_leftcolmark * divs content) * @param out The writer. * @throws IOException If writing fails. * @since 5.4 */ public static void printTitle(String fieldId, String title, boolean required, boolean hideLabel, Writer out) throws IOException { out.write("<div class=\"form_leftcol\""); if (hideLabel) { out.write(" style=\"display: none;\""); } if (title != null && title.length() > 0) { title = StringEscapeUtils.escapeHtml4(title); } else { title = " "; } out.write(">"); out.write("<div class=\"form_leftcollabel\">"); if (fieldId != null) { fieldId = StringEscapeUtils.escapeHtml4(fieldId); out.write("<label for=\"" + fieldId + "\">" + title + "</label>"); } else { out.write("<span>" + title + "</span>"); } out.write("</div>"); out.write("<div class=\"form_leftcolmark\">"); if (!hideLabel) { if (required) { out.write(" *"); } else { out.write(" "); } } out.write("</div>"); out.write("</div>\n"); }
From source file:net.ontopia.topicmaps.nav2.portlets.pojos.Wiki.java
public static void render(String text, Writer out, TopicMapIF topicmap, Map params) throws IOException { out.write("<p>"); int old = 0;/*from w w w. ja v a 2 s. c o m*/ for (int ix = 0; ix < text.length(); ix++) { String output = null; int end = ix; if (text.charAt(ix) == '\n') { if (ix + 1 == text.length()) { output = ""; end = ix; } else if (text.charAt(ix + 1) == '\n') { output = "</p><p>"; end = ix + 1; } else if (text.charAt(ix + 1) == '\r' && text.charAt(ix + 2) == '\n') { output = "</p><p>"; end = ix + 2; } else if (text.charAt(ix + 1) == '*') { int pos = findNextDoubleNewline(text, ix + 1, out); output = makeList(text.substring(ix + 1, pos)); end = pos + 1; } } else if (text.charAt(ix) == '=') { int pos = text.indexOf('=', ix + 1); output = "<h2>" + text.substring(ix + 1, pos) + "</h2>"; end = pos; } else if (text.charAt(ix) == '<') { if (text.substring(ix, ix + 5).equals("<pre>")) { int pos = text.indexOf("</pre>", ix + 1); output = "<pre>" + escape(text.substring(ix + 5, pos)) + "</pre>"; end = pos + 6; } else if (text.substring(ix, ix + 7).equals("<tolog>")) { int pos = text.indexOf("</tolog>", ix + 1); String query = text.substring(ix + 7, pos); output = runQuery(query, topicmap, params); end = pos + 7; // ? } } else if (text.charAt(ix) == '\'') { int length = 0; String gi = null; if (text.substring(ix, ix + 3).equals("'''")) { length = 3; gi = "b"; } else if (text.substring(ix, ix + 2).equals("''")) { length = 2; gi = "i"; } if (gi != null) { int pos = text.indexOf("''" + (length == 3 ? "'" : ""), ix + length); output = "<" + gi + ">" + text.substring(ix + length, pos) + "</" + gi + ">"; end = pos + length - 1; } } else if (text.charAt(ix) == '[') { int pos = text.indexOf(']', ix); String name = text.substring(ix + 1, pos); TopicIF topic = getTopic(name, topicmap); output = getString(topic, params); end = pos; } if (output != null) { out.write(text.substring(old, ix)); out.write(output); ix = end; old = end + 1; } } out.write(escape(text.substring(old))); out.write("</p>"); }
From source file:org.ambientdynamix.web.WebUtils.java
/** * xports an certificate to a file.//from ww w. ja v a 2 s. c o m * * @param cert * The certificate to export. * @param file * The destination file. * @param binary * True if the cert should be written as a binary file; false to encode using Base64. */ public static void exportCertificate(java.security.cert.Certificate cert, File file, boolean binary) { Log.i(TAG, "Writing cert to: " + file.getAbsolutePath()); try { // Get the encoded form which is suitable for exporting byte[] buf = cert.getEncoded(); FileOutputStream os = new FileOutputStream(file); if (binary) { // Write in binary form os.write(buf); } else { // Write in text form Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write("-----BEGIN CERTIFICATE-----\n"); Base64.encodeBase64(buf); wr.write("\n-----END CERTIFICATE-----\n"); wr.flush(); } os.close(); } catch (Exception e) { Log.w(TAG, "Error writing cert for " + file); } }
From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverterTest.java
private static Answer<Object> write(final int writerIndex, final String string) { return new Answer<Object>() { @Override//from w w w . j a va 2s .co m public Object answer(InvocationOnMock invocation) throws IOException { Writer writer = invocation.getArgumentAt(writerIndex, Writer.class); writer.write(string); return null; } }; }
From source file:core.RESTCalls.RESTPost.java
public static String httpPost(String urlStr, String[] paramName, String[] paramVal) throws Exception { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true);// w w w . j a v a2s. c o m conn.setDoInput(true); conn.setUseCaches(false); conn.setAllowUserInteraction(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStream out = conn.getOutputStream(); Writer writer = new OutputStreamWriter(out, "UTF-8"); for (int i = 0; i < paramName.length; i++) { writer.write(paramName[i]); writer.write("="); writer.write(URLEncoder.encode(paramVal[i], "UTF-8")); writer.write("&"); } writer.close(); out.close(); if (conn.getResponseCode() != 200) throw new IOException(conn.getResponseMessage()); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) sb.append(line + "\n"); rd.close(); conn.disconnect(); return sb.toString(); }