List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:FileTableHTML.java
public static String makeHTMLTable(String dirname) { // Look up the contents of the directory File dir = new File(dirname); String[] entries = dir.list(); // Set up an output stream we can print the table to. // This is easier than concatenating strings all the time. StringWriter sout = new StringWriter(); PrintWriter out = new PrintWriter(sout); // Print the directory name as the page title out.println("<H1>" + dirname + "</H1>"); // Print an "up" link, unless we're already at the root String parent = dir.getParent(); if ((parent != null) && (parent.length() > 0)) out.println("<A HREF=\"" + parent + "\">Up to parent directory</A><P>"); // Print out the table out.print("<TABLE BORDER=2 WIDTH=600><TR>"); out.print("<TH>Name</TH><TH>Size</TH><TH>Modified</TH>"); out.println("<TH>Readable?</TH><TH>Writable?</TH></TR>"); for (int i = 0; i < entries.length; i++) { File f = new File(dir, entries[i]); out.println("<TR><TD>" + (f.isDirectory() ? "<a href=\"" + f + "\">" + entries[i] + "</a>" : entries[i]) + "</TD><TD>" + f.length() + "</TD><TD>" + new Date(f.lastModified()) + "</TD><TD align=center>" + (f.canRead() ? "x" : " ") + "</TD><TD align=center>" + (f.canWrite() ? "x" : " ") + "</TD></TR>"); }/* www. j av a 2 s .com*/ out.println("</TABLE>"); out.close(); // Get the string of HTML from the StringWriter and return it. return sout.toString(); }
From source file:IO.java
public static void writeData(int[][] data, int nData, int nDim, String filepath) { File file = new File(filepath); PrintWriter writer; try {/* w w w . j a v a 2s .co m*/ writer = new PrintWriter(file); for (int i = 0; i < nData; i++) { for (int j = 0; j < nDim; j++) { if (j == nDim - 1) { writer.print(data[i][j]); } else { writer.print(data[i][j] + ","); } } writer.println(); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.servoy.j2db.server.ngclient.template.FormLayoutStructureGenerator.java
private static void generateLayoutContainer(LayoutContainer container, ServoyDataConverterContext context, PrintWriter writer, boolean design, boolean highlight) throws IOException { if (highlight) writer.print("<div class='highlight_element'>"); writer.print("<"); writer.print(container.getTagType()); if (design) { writer.print(" svy-id='"); writer.print(container.getUUID().toString()); writer.print("'"); WebComponentPackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getInstance() .getLayoutSpecifications().get(container.getPackageName()); WebLayoutSpecification spec = null; if (pkg != null && (spec = pkg.getSpecification(container.getSpecName())) != null) { List<String> allowedChildren = spec.getAllowedChildren(); if (allowedChildren.size() > 0) { writer.print(" svy-allowed-children='"); writer.print("[" + StringUtil.join(allowedChildren, ",") + "]"); writer.print("'"); }//from w w w .j ava2 s. c o m writer.print(" svy-layoutname='"); writer.print(spec.getName()); writer.print("'"); if (spec.getDesignStyleClass() != null) { writer.print(" svy-designclass='"); writer.print(spec.getDesignStyleClass()); writer.print("'"); } } } if (container.getElementId() != null) { writer.print(" id='"); writer.print(container.getElementId()); writer.print("' "); } Map<String, String> attributes = container.getAttributes(); if (attributes != null) { for (Entry<String, String> entry : attributes.entrySet()) { writer.print(" "); StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer); if (entry.getValue() != null && entry.getValue().length() > 0) { writer.print("=\""); StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer); writer.print("\""); } } } writer.println(">"); Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR); while (components.hasNext()) { IPersist component = components.next(); if (component instanceof LayoutContainer) { generateLayoutContainer((LayoutContainer) component, context, writer, design, highlight); } else if (component instanceof IFormElement) { FormLayoutGenerator.generateFormElement(writer, FormElementHelper.INSTANCE.getFormElement((IFormElement) component, context, null), design, highlight); } } writer.print("</"); writer.print(container.getTagType()); writer.print(">"); if (highlight) writer.print("</div>"); }
From source file:IO.java
public static void writeData(double[][] data, int nData, int nDim, String filepath) { File file = new File(filepath); PrintWriter writer; try {/* w w w . jav a2 s . com*/ writer = new PrintWriter(file); for (int i = 0; i < nData; i++) { for (int j = 0; j < nDim; j++) { if (j == nDim - 1) { writer.print(data[i][j]); } else { writer.print(data[i][j] + ","); } } writer.println(); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java
private static void writeExperimentDesignTypes(Experiment experiment, String desc, PrintWriter out) { out.print("!Series_overall_design="); if (experiment.getExperimentDesignTypes().isEmpty()) { out.println(desc);/*from w ww . j av a 2s. c o m*/ } else { String semi = "\""; for (final Term edt : experiment.getExperimentDesignTypes()) { out.print(semi); semi = "\"; \""; out.print(edt.getValue()); out.print(" ("); out.print(edt.getSource().getName()); out.print(')'); } out.println('"'); } }
From source file:com.zimbra.common.util.TemplateCompiler.java
private static void printLine(PrintWriter out, String... ss) { for (String s : ss) { out.print(s); }/*from ww w.j av a2 s . com*/ }
From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java
private static void writeSeriesSection(Experiment experiment, String permaLinkUrl, PrintWriter out) { out.print("^SERIES="); out.println(experiment.getPublicIdentifier()); out.print("!Series_title="); out.println(experiment.getTitle());/* w ww .j av a2 s. c o m*/ out.print("!Series_summary="); final String desc = StringUtils.isNotBlank(experiment.getDescription()) ? experiment.getDescription() : experiment.getTitle(); out.println(desc); writeExperimentDesignTypes(experiment, desc, out); for (final Publication pub : experiment.getPublications()) { out.print("!Series_pubmed_id="); out.println(pub.getPubMedId()); } for (final ExperimentContact c : experiment.getExperimentContacts()) { writeExperimentContact(c, out); } out.print("!Series_web_link="); out.println(permaLinkUrl); for (final Hybridization h : experiment.getHybridizations()) { out.print("!Series_sample_id="); out.println(h.getName()); } }
From source file:net.mybox.mybox.Server.java
private static void log(String message) { // TODO: change this to be a static PrintWriter opened at construction time PrintWriter out = null; try {//from w w w .j a v a2 s .c o m out = new PrintWriter(new FileWriter(logFile, true)); } catch (Exception e) { System.out.println("Unable to open log file: " + e); } out.print(message); out.close(); }
From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java
/** * Includes the HTML document in the response * //from w ww .ja v a 2s . c o m * @param response HTTP response * @param method HTTP method * @param url document url * @param loginUrl login url * @param contentType content type * * @throws IOException */ public static void returnHTML(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl, String contentType) throws IOException { logger.debug("Returning an HTML document"); //Get writer PrintWriter out = null; try { out = response.getWriter(); if (out != null) { //set content out.print(method.getResponseBodyAsString()); //close writer out.close(); response.setHeader("Content-Type", contentType); } } catch (Exception e) { logger.error("Error when returning HTML content: " + e.getMessage(), e); //protection if (out != null) { out.close(); } } }
From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java
/** * Outputs spaces in the left hand margin appropriate for the given nesting * level./*from ww w . j a v a 2s . c om*/ * * @param out * PrintWriter to write the output to * @param nestLevel * the nesting level */ private static void indent(PrintWriter out, int nestLevel) { int size = nestLevel * 3; for (int i = 0; i < size; i++) { out.print(' '); } }