List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:IORoutines.java
public static void saveStrings(File file, java.util.Collection list) throws IOException { BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file)); try {//w ww. j av a 2s .c o m PrintWriter writer = new PrintWriter(bout); java.util.Iterator i = list.iterator(); while (i.hasNext()) { String text = (String) i.next(); writer.println(text); } writer.flush(); } finally { bout.close(); } }
From source file:forge.util.FileUtil.java
/** * <p>/*w ww. j a va2 s . c o m*/ * writeFile. * </p> * * @param file * a {@link java.io.File} object. * @param data * a {@link java.util.List} object. */ public static void writeFile(File file, Collection<?> data) { try { PrintWriter p = new PrintWriter(file); for (Object o : data) { p.println(o); } p.close(); } catch (final Exception ex) { throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex); } }
From source file:gda.util.persistence.LocalParameters.java
/** * @param configDir//w ww . jav a2 s . co m * @param configName * @param createIfMissing * @param createAlways true if existing config in the cache is to be thrown away - re-reads the underlying file * @return XMLConfiguration * @throws ConfigurationException * @throws IOException */ public synchronized static XMLConfiguration getXMLConfiguration(String configDir, String configName, Boolean createIfMissing, boolean createAlways) throws ConfigurationException, IOException { // Instantiate the Configuration if it has not been instantiated if (configDir == null || configDir.isEmpty()) throw new IllegalArgumentException("configDir is null or empty"); if (!configDir.endsWith(File.separator)) configDir += File.separator; final String fullName = getFullName(configDir, configName); if (createAlways && configList.containsKey(fullName)) { configList.remove(fullName); } if (configList.containsKey(fullName) == false) { XMLConfiguration config; // Try to open the file try { config = loadConfigurationFromFile(fullName); } catch (ConfigurationException e) // catch (NoClassDefFoundError e) { // Assume the error occured because the file does not exist // Throw exception if createIfMissing is false if (createIfMissing == false) { logger.error("Could not load " + configDir + configName + ".xml which will not be created"); throw new ConfigurationException(e); } // else try to make it... try { File dir = new File(configDir); if (!dir.exists()) if (!dir.mkdirs()) { throw new FileNotFoundException("Couldn't create directory: " + dir); } File file = new File(fullName); PrintWriter out = new PrintWriter(new FileWriter(file)); out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>"); out.println("<" + configName + ">"); out.println("</" + configName + ">"); out.close(); } catch (IOException ee) { logger.error("Failed trying to create non-existent file " + fullName); throw new IOException(ee); } // ... and read it again try { config = loadConfigurationFromFile(fullName); } catch (ConfigurationException ee) { logger.error("Failed trying to read newly-created file " + fullName); throw new ConfigurationException(e); } logger.debug("Created configuration file: " + fullName); } // endif - create a missing file config.setReloadingStrategy(new FileChangedReloadingStrategy()); configList.put(fullName, config); logger.debug("Loaded the configuration file: " + fullName); } // endif - instantiate a new configuration // return the configuration object return configList.get(fullName); }
From source file:com.act.lcms.v2.fullindex.Searcher.java
private static void writeOutput(PrintWriter writer, List<TMzI> results) throws IOException { int counter = 0; writer.println(OUTPUT_HEADER); for (TMzI triple : results) { writer.format("%d\t%.6f\t%.6f\t%.6f\n", counter, triple.getTime(), triple.getMz(), triple.getIntensity());//from w ww . j a va 2 s.c o m counter++; } writer.flush(); }
From source file:com.bc.fiduceo.post.PostProcessingTool.java
static void printUsageTo(OutputStream outputStream) { final PrintWriter writer = new PrintWriter(outputStream); writer.println("post-processing-tool version " + VERSION_NUMBER); writer.println();//from w w w .j a v a2s . c o m final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(writer, 120, "post-processing-tool <options>", "Valid options are:", getOptions(), 3, 3, ""); writer.flush(); }
From source file:fr.jayasoft.ivy.Main.java
private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, String[] confs, String outFile) { try {//from w w w . j a v a2 s . com String pathSeparator = System.getProperty("path.separator"); StringBuffer buf = new StringBuffer(); XmlReportParser parser = new XmlReportParser(); Collection all = new LinkedHashSet(); for (int i = 0; i < confs.length; i++) { Artifact[] artifacts = parser.getArtifacts(md.getModuleRevisionId().getModuleId(), confs[i], cache); all.addAll(Arrays.asList(artifacts)); } for (Iterator iter = all.iterator(); iter.hasNext();) { Artifact artifact = (Artifact) iter.next(); buf.append(ivy.getArchiveFileInCache(cache, artifact).getCanonicalPath()); if (iter.hasNext()) { buf.append(pathSeparator); } } PrintWriter writer = new PrintWriter(new FileOutputStream(outFile)); writer.println(buf.toString()); writer.close(); System.out.println("cachepath output to " + outFile); } catch (Exception ex) { throw new RuntimeException("impossible to build ivy cache path: " + ex.getMessage(), ex); } }
From source file:it.jnrpe.server.CJNRPEServer.java
/** * Generates a simple configuration file * @param cl The command line//from w w w .j a va 2s .co m */ private static void generateScheletonConfig(String sFilePath) { CStreamManager mgr = new CStreamManager(); try { PrintWriter w = (PrintWriter) mgr .handle(new PrintWriter(new BufferedOutputStream(new FileOutputStream(new File(sFilePath))))); w.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); w.println("<config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:noNamespaceSchemaLocation=\"http://jnrpe.sourceforge.net/jnrpeConfig.xsd\">"); w.println(" <!-- Main Server Configuration -->"); w.println(" <server accept-params=\"true\">"); w.println(" <!-- The following configuration, will bind to"); w.println(" the 127.0.0.1 and will allow only local requests -->"); w.println(" <bind address=\"127.0.0.1:5666\" SSL=\"false\"/>"); w.println(" <allow ip=\"127.0.0.1\"/>"); w.println(" <!-- The directory where all plugins resides"); w.println(" is ./plugins - inside this directory you'll"); w.println(" have one directory for each plugin. -->"); w.println(" <plugin path=\"./plugins\"/>"); w.println(" </server>"); w.println(" <commands>"); CPluginFactory factory = CPluginFactory.getInstance(); Set vPlugins = factory.getPluginList(); //for (String sPluginName : vPlugins) for (Iterator iter = vPlugins.iterator(); iter.hasNext();) { String sPluginName = (String) iter.next(); CPluginProxy pp = factory.getPlugin(sPluginName); w.println(" <command name=\"" + sPluginName + "\" plugin_name=\"" + sPluginName + "\">"); Collection vOptions = pp.getOptions(); int i = 1; w.println(" <!-- WARNING!! -->"); w.println( " <!-- Generated argument list, won't take care of mutually exclusive arguments! -->"); for (Iterator iterator = vOptions.iterator(); iterator.hasNext();) { COption opt = (COption) iterator.next(); w.print(" <arg name=\"" + opt.getLongOpt() + "\" "); if (opt.hasArgs()) w.print(" value=\"" + "$ARG" + i++ + "$\" "); w.println("/>"); } w.println(" </command>"); } w.println(" </commands>"); w.println("</config>"); } catch (Exception e) { System.out.println("ERROR GENERATING CONFIGURATION FILE : " + e.getMessage()); System.exit(-1); } finally { mgr.closeAll(); } System.out.println("FILE GENERATED SUCCESSFULLY"); System.exit(0); }
From source file:org.jodconverter.cli.Convert.java
private static void printErr(final String message, final Object... values) { final PrintWriter writer = new PrintWriter(System.err); // NOSONAR writer.println(String.format(message, values)); writer.flush();/*from w w w . j a v a2 s .c om*/ }
From source file:org.jodconverter.cli.Convert.java
private static void printInfo(final String message, final Object... values) { final PrintWriter writer = new PrintWriter(System.out); // NOSONAR writer.println(String.format(message, values)); writer.flush();/*from w w w . j a v a 2s . co m*/ }
From source file:biz.wolschon.finance.jgnucash.helper.HttpFetcher.java
/** * Fetch the given URL with http-basic-auth. * @param url the URL// ww w .jav a 2s . c o m * @param username username * @param password password * @return the page-content or null */ public static String fetchURL(final URL url, final String username, final String password) { StringWriter sw = new StringWriter(); try { PrintWriter pw = new PrintWriter(sw); InputStream content = fetchURLStream(url, username, password); BufferedReader in = new BufferedReader(new InputStreamReader(content)); String line; while ((line = in.readLine()) != null) { pw.println(line); } } catch (MalformedURLException e) { e.printStackTrace(); LOGGER.error("cannot fetch malformed URL " + url, e); return null; } catch (IOException e) { e.printStackTrace(); LOGGER.error("cannot fetch URL " + url, e); return null; } return sw.toString(); }