List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:edu.sdsc.solr.lemmatization.LemmatizationWriter.java
static void writeSynonyms(Multimap<String, String> synonyms, Writer writer) throws IOException { for (Entry<String, Collection<String>> entry : synonyms.asMap().entrySet()) { entry.getValue().add(entry.getKey()); writer.write(Joiner.on(", ").join(entry.getValue()) + "\n"); }//from w w w .j a v a2 s . c o m }
From source file:com.prowidesoftware.swift.io.RJEWriter.java
/** * Writes the message content into the writer in RJE format * @param msg SWIFT MT content to write/*from www .j ava 2s .c o m*/ * @param writer * @throws IOException if an I/O error occurs */ public static void write(final String msg, final Writer writer) throws IOException { Validate.notNull(writer, "writer has not been initialized"); Validate.notNull(msg, "message to write cannot be null"); writer.write(msg); writer.write(FINWriterVisitor.SWIFT_EOL); writer.write(RJEReader.SPLITCHAR); writer.write(FINWriterVisitor.SWIFT_EOL); }
From source file:citibob.licensor.MakeLauncher.java
/** * /* w w w . java 2s . com*/ * @param version * @param configDir * @param outJar * @param spassword * @throws java.lang.Exception */ public static void makeLauncher(String version, File configDir, File outJar, String spassword) throws Exception { File oaDir = ClassPathUtils.getMavenProjectRoot(); File oalaunchDir = new File(oaDir, "../oalaunch"); File oasslDir = new File(oaDir, "../oassl"); File keyDir = new File(oasslDir, "keys/client"); File tmpDir = new File(".", "tmp"); FileUtils.deleteDirectory(tmpDir); tmpDir.mkdirs(); // Find the oalaunch JAR file File oalaunchJar = null; File[] files = new File(oalaunchDir, "target").listFiles(); for (File f : files) { if (f.getName().startsWith("oalaunch") && f.getName().endsWith(".jar")) { oalaunchJar = f; break; } } // Unjar the oalaunch.jar file into the temporary directory exec(tmpDir, "jar", "xvf", oalaunchJar.getAbsolutePath()); File tmpOalaunchDir = new File(tmpDir, "oalaunch"); File tmpConfigDir = new File(tmpOalaunchDir, "config"); // Read app.properties Properties props = new Properties(); InputStream in = new FileInputStream(new File(configDir, "app.properties")); props.load(in); in.close(); // Re-do the config dir FileUtils.deleteDirectory(tmpConfigDir); FileFilter ff = new FileFilter() { public boolean accept(File f) { if (f.getName().startsWith(".")) return false; if (f.getName().endsWith("~")) return false; return true; } }; FileUtils.copyDirectory(configDir, tmpConfigDir, ff); // Set up to encrypt char[] password = null; PBECrypt pbe = new PBECrypt(); if (spassword != null) password = spassword.toCharArray(); // Encrypt .properties files if needed if (password != null) { for (File fin : configDir.listFiles()) { if (fin.getName().endsWith(".properties") || fin.getName().endsWith(".jks")) { File fout = new File(tmpConfigDir, fin.getName()); pbe.encrypt(fin, fout, password); } } } // Copy the appropriate key and certificate files String dbUserName = props.getProperty("db.user", null); File[] jksFiles = new File[] { new File(keyDir, dbUserName + "-store.jks"), new File(keyDir, dbUserName + "-trust.jks") }; for (File fin : jksFiles) { if (!fin.exists()) { System.out.println("Missing jks file: " + fin.getName()); continue; } File fout = new File(tmpConfigDir, fin.getName()); if (password != null) { System.out.println("Encrypting " + fin.getName()); pbe.encrypt(fin, fout, password); } else { System.out.println("Copying " + fin.getName()); FileUtils.copyFile(fin, fout); } } // Use a downloaded JNLP file, not a static one. new File(tmpOalaunchDir, "offstagearts.jnlp").delete(); // Open properties file, which we will write to... File oalaunchProperties = new File(tmpDir, "oalaunch/oalaunch.properties"); Writer propertiesOut = new FileWriter(oalaunchProperties); propertiesOut.write( "jnlp.template.url = " + "http://offstagearts.org/releases/offstagearts/offstagearts_oalaunch-" + version + ".jnlp.template\n"); String configName = outJar.getName(); int dot = configName.lastIndexOf(".jar"); if (dot >= 0) configName = configName.substring(0, dot); propertiesOut.write("config.name = " + configName + "\n"); propertiesOut.close(); // Jar it back up exec(tmpDir, "jar", "cvfm", outJar.getAbsolutePath(), "META-INF/MANIFEST.MF", "."); // // Sign it // exec(null, "jarsigner", "-storepass", "keyst0re", outJar.getAbsolutePath(), // "offstagearts"); // Remove the tmp directory FileUtils.deleteDirectory(tmpDir); }
From source file:com.boundlessgeo.geoserver.json.JSONWrapper.java
/** * Encodes a wrapper as JSON.//from w w w .j a v a2 s. c om * * @param obj The wrapper. * @param out Target writer. * */ public static void write(Object value, Writer out) throws IOException { value = wrapOrSelf(value); if (value == null) { out.write("null"); out.flush(); } else if (value instanceof JSONWrapper) { ((JSONWrapper<?>) value).write(out); } else { JSONValue.writeJSONString(value, out); } }
From source file:com.magic.util.FileUtil.java
public static void writeString(String path, String name, String s) throws IOException { Writer out = getBufferedWriter(path, name); try {//www. j a va 2 s . c o m out.write(s + System.getProperty("line.separator")); } catch (IOException e) { Debug.logError(e, module); throw e; } finally { if (out != null) { try { out.close(); } catch (IOException e) { Debug.logError(e, module); } } } }
From source file:ca.uqac.dim.net.verify.NetworkChecker.java
/** * Runs the NuSMV program as a spawned command-line process, and passes the * file to process through that process' standard input * @param file_contents A String containing the NuSMV model to process */// www .j a v a 2 s . c o m private static RuntimeInfos runNuSMV(String file_contents) throws IOException, InterruptedException { StringBuilder sb = new StringBuilder(); Runtime rt = Runtime.getRuntime(); long time_start = 0, time_end = 0; // Start NuSMV, and feed the model through its standard input time_start = System.currentTimeMillis(); Process p = rt.exec(NUSMV_EXEC); OutputStream o = p.getOutputStream(); InputStream i = p.getInputStream(); InputStream e = p.getErrorStream(); Writer w = new PrintWriter(o); w.write(file_contents); w.close(); // Close stdin so NuSMV can start processing it // Wait for NuSMV to be done, then collect its standard output int exitVal = p.waitFor(); if (exitVal != 0) throw new IOException("NuSMV's return value indicates an error in processing its input"); BufferedReader br = new BufferedReader(new InputStreamReader(i)); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } time_end = System.currentTimeMillis(); i.close(); // Close stdout e.close(); // Close stderr return new RuntimeInfos(sb.toString(), time_end - time_start); }
From source file:com.moss.posixfifosockets.PosixFifoSocket.java
public static PosixFifoSocket newClientConnection(PosixFifoSocketAddress address, int timeoutMillis) throws IOException { final Log log = LogFactory.getLog(PosixFifoSocket.class); if (!address.controlPipe().exists()) { throw new IOException("There is no server at " + address); }// www . j a v a 2 s .c o m File in; File out; File control; long id; do { id = r.nextLong(); in = new File(address.socketsDir(), id + ".fifo.out"); out = new File(address.socketsDir(), id + ".fifo.in"); control = new File(address.socketsDir(), id + ".fifo.control"); } while (out.exists() || in.exists()); createFifo(in); createFifo(control); final String registrationString = "{" + id + "}"; if (log.isDebugEnabled()) log.debug("Sending registration " + registrationString); Writer w = new FileWriter(address.controlPipe()); w.write(registrationString); w.flush(); if (log.isDebugEnabled()) log.debug("Sent Registration " + registrationString); PosixFifoSocket socket = new PosixFifoSocket(id, in, out); Reader r = new FileReader(control); StringBuilder text = new StringBuilder(); for (int c = r.read(); c != -1 && c != '\n'; c = r.read()) { // READ UNTIL THE FIRST LINE BREAK text.append((char) c); } r.close(); if (!control.delete()) { throw new RuntimeException("Could not delete file:" + control.getAbsolutePath()); } if (!text.toString().equals("OK")) { throw new RuntimeException("Connection error: received \"" + text + "\""); } return socket; }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.RecommendationToJson.java
private static void saveResults(JSONArray recomendations, String id) { Writer out; try {//from w w w . j av a2s . c o m out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("data_toVisualize/data_recommendation/recommendation_" + id + ".json"), "UTF-8")); try { out.write(recomendations.toJSONString()); out.close(); } catch (IOException e) { e.printStackTrace(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.cloudhopper.sxmp.SxmpWriter.java
static private void writeOperationEndTag(Writer out) throws IOException { out.write("</operation>\n"); }
From source file:com.day.cq.wcm.foundation.forms.LayoutHelper.java
/** * Print the description/*from w ww.j av a 2s .c om*/ * <p/> * If <code>fieldId</code> is set the description will be enclosed in a label * for accessibility. This facility should only be used when the field has no * title, or the title is not used as a label for some reason. * <p/> * The <code>description</code> is encoded using * {@link StringEscapeUtils#escapeHtml4(String)} before it is written to * the {@link Writer}. * * @param descr The description of the field (or null) * @param out The writer. * @throws IOException If writing fails. */ public static void printDescription(String fieldId, String descr, Writer out) throws IOException { out.write("<div class=\"form_row_description\">"); if (descr != null && descr.length() > 0) { descr = StringEscapeUtils.escapeHtml4(descr); if (fieldId != null) { fieldId = StringEscapeUtils.escapeHtml4(fieldId); out.write("<label for=\"" + fieldId + "\">" + descr + "</label>"); } else { out.write("<span>" + descr + "</span>"); } } out.write("</div>\n"); }