List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:de.citec.sc.matoll.utils.visualizeSPARQL.java
private static void writePatterns(List<SparqlPattern> Patterns, Language language) { String prefix = "\\documentclass{scrartcl}\n" + "\\usepackage{mathtools}\n" + "\\usepackage{tikz}\n" + "\\usetikzlibrary{trees,positioning}\n" + "\n" + "\\begin{document}\n"; String suffix = "\\end{document}"; String output = ""; System.out.println("Starting visualisation"); for (SparqlPattern pattern : Patterns) { String tmp = doVisual(pattern.getQuery(), pattern.getID().replace("_", "\\_")) + "\n\n\n"; String[] triple = pattern.getQuery().split("\n"); for (String t : triple) { tmp = "%" + t + "\n" + tmp; }/* ww w .java 2 s .co m*/ if (tmp != null) output += tmp; else System.out.println(pattern.getID() + " could not be visualized"); } PrintWriter writer; try { writer = new PrintWriter("sparql_tree_" + language.toString() + ".tex"); writer.write(prefix + output + suffix); writer.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gov.nih.nci.caintegrator.application.util.CSVUtil.java
public static void renderCSV(HttpServletResponse response, List<List> csv) { PrintWriter out = null; long randomness = System.currentTimeMillis(); response.setContentType("application/csv"); response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv"); try {// w w w .j ava2 s . c o m for (List row : csv) { out = response.getWriter(); out.write(StringUtils.join(row.toArray(), ",") + "\r\n"); out.flush(); } } catch (Exception e) { out.write("error generating report"); } }
From source file:gov.loc.ndmso.proxyfilter.RequestProxy.java
public static void copyStreamText(String in, PrintWriter out) throws IOException { out.write(in); }
From source file:edu.cornell.med.icb.goby.modes.CountsArchiveToUnionPeaksAnnotationMode.java
public static void writeAnnotations(final String outputFileName, final ObjectList<Annotation> annotationList, final boolean append) { final File outputFile = new File(outputFileName); PrintWriter writer = null; try {/* w w w . j a v a2s . c om*/ if (!outputFile.exists()) { writer = new PrintWriter(outputFile); writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } final ObjectListIterator<Annotation> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final Annotation annotation = annotIterator.next(); annotation.write(writer); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.voa.weixin.utils.HttpUtils.java
public static void write(HttpServletResponse response, String message) throws IOException { PrintWriter writer = null; try {/*from www . ja v a 2 s .co m*/ response.setHeader("Charset", "UTF-8"); response.setCharacterEncoding("UTF-8"); writer = response.getWriter(); writer.write(message); } finally { if (writer != null) writer.close(); } }
From source file:io.proleap.cobol.TestGenerator.java
public static void generateTestClass(final File cobolInputFile, final File outputDirectory, final String packageName) throws IOException { final File parentDirectory = cobolInputFile.getParentFile(); final String inputFilename = getInputFilename(cobolInputFile); final File outputFile = new File( outputDirectory + "/" + inputFilename + OUTPUT_FILE_SUFFIX + JAVA_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating unit test {}.", outputFile); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); final String cobolInputFileName = cobolInputFile.getPath().replace("\\", "/"); final CobolSourceFormat format = getCobolSourceFormat(parentDirectory); pWriter.write("package " + packageName + ";\n"); pWriter.write("\n"); pWriter.write("import java.io.File;\n"); pWriter.write("\n"); pWriter.write("import io.proleap.cobol.applicationcontext.CobolGrammarContextFactory;\n"); pWriter.write("import io.proleap.cobol.preprocessor.CobolPreprocessor.CobolSourceFormatEnum;\n"); pWriter.write("import io.proleap.cobol.runner.CobolParseTestRunner;\n"); pWriter.write("import io.proleap.cobol.runner.impl.CobolParseTestRunnerImpl;\n"); pWriter.write("import org.junit.Test;\n"); pWriter.write("\n"); pWriter.write("public class " + inputFilename + "Test {\n"); pWriter.write("\n"); pWriter.write(" @Test\n"); pWriter.write(" public void test() throws Exception {\n"); pWriter.write(" CobolGrammarContextFactory.configureDefaultApplicationContext();\n"); pWriter.write("\n"); pWriter.write(" final File inputFile = new File(\"" + cobolInputFileName + "\");\n"); pWriter.write(" final CobolParseTestRunner runner = new CobolParseTestRunnerImpl();\n"); pWriter.write(" runner.parseFile(inputFile, CobolSourceFormatEnum." + format + ");\n"); pWriter.write(" }\n"); pWriter.write("}"); pWriter.flush();//www.jav a 2 s .c o m pWriter.close(); } }
From source file:edu.cornell.med.icb.goby.modes.AggregatePeaksByPeakDistanceMode.java
public static void writeAnnotations(final String outputFileName, final ObjectList<Annotation> annotationList, final boolean append) { PrintWriter writer = null; final File outputFile = new File(outputFileName); try {/*from w ww . ja v a 2 s . co m*/ if (!outputFile.exists()) { writer = new PrintWriter(outputFile); writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } if (writer != null) { final ObjectListIterator<Annotation> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final Annotation annotation = annotIterator.next(); annotation.write(writer); } } else { System.err.println("Cannot write annotations to file: " + outputFileName); System.err.println("The writer failed to initialize."); System.exit(1); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }
From source file:Main.java
/** * Performs the actual recursive dumping of a DOM tree to a given * <CODE>PrintWriter</CODE>. Note that dump is intended to be a detailed * debugging aid rather than pretty to look at. * //from w w w . j av a 2 s . c om * @param out The <CODE>PrintWriter</CODE> to write to. * @param node The <CODE>Node</CODE> under consideration. * @param indent The level of indentation. * @see #dump(PrintWriter, Node) * @since TFP 1.0 */ private static void doDump(PrintWriter out, final Node node, int indent) { if (node != null) { for (int index = 0; index < indent; ++index) out.write(' '); switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { Document document = (Document) node; out.println("DOCUMENT:"); doDump(out, document.getDoctype(), indent + 1); doDump(out, document.getDocumentElement(), indent + 1); break; } case Node.DOCUMENT_TYPE_NODE: { DocumentType type = (DocumentType) node; out.println("DOCTYPE: [" + "name=" + format(type.getName()) + "," + "publicId=" + format(type.getPublicId()) + "," + "systemId=" + format(type.getSystemId()) + "]"); break; } case Node.ELEMENT_NODE: { Element element = (Element) node; out.println("ELEMENT: [" + "ns=" + format(element.getNamespaceURI()) + "," + "name=" + format(element.getLocalName()) + "]"); NamedNodeMap attrs = element.getAttributes(); for (int index = 0; index < attrs.getLength(); ++index) doDump(out, attrs.item(index), indent + 1); for (Node child = element.getFirstChild(); child != null;) { doDump(out, child, indent + 1); child = child.getNextSibling(); } break; } case Node.ATTRIBUTE_NODE: { Attr attr = (Attr) node; out.println("ATTRIBUTE: [" + "ns=" + format(attr.getNamespaceURI()) + "," + "prefix=" + format(attr.getPrefix()) + "," + "name=" + format(attr.getLocalName()) + "," + "value=" + format(attr.getNodeValue()) + "]"); break; } case Node.TEXT_NODE: { Text text = (Text) node; out.println("TEXT: [" + format(text.getNodeValue()) + "]"); for (Node child = text.getFirstChild(); child != null;) { doDump(out, child, indent + 1); child = child.getNextSibling(); } break; } case Node.CDATA_SECTION_NODE: { CDATASection data = (CDATASection) node; out.println("CDATA: [" + format(data.getNodeValue()) + "]"); break; } case Node.COMMENT_NODE: { Comment comm = (Comment) node; out.println("COMMENT: [" + format(comm.getNodeValue()) + "]"); break; } default: out.println("UNKNOWN: [type=" + node.getNodeType() + "]"); break; } } }
From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java
/** * send a HTTP POST request//from w ww.j av a2 s .co m * @param param * @param input_url * @return */ public static String POST(String param, String input_url) { try { URL url = new URL(input_url); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoOutput(true); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/xml"); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); PrintWriter xmlOut = new PrintWriter(con.getOutputStream()); xmlOut.write(param); xmlOut.flush(); BufferedReader response = new BufferedReader(new InputStreamReader(con.getInputStream())); String result = ""; String line; while ((line = response.readLine()) != null) { result += "\n" + line; } return result.toString(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.day.cq.wcm.foundation.forms.FieldHelper.java
/** * Write client regexp text.//from w ww . j a va 2 s . c o m */ public static void writeClientRegexpText(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final FieldDescription desc, final String regexp) throws IOException { final PrintWriter out = response.getWriter(); final String id = getClientFieldQualifier(request, desc); out.write("{var obj ="); out.write(id); out.write(";" + "if ( cq5forms_isArray(obj)) {" + "for(i=0;i<obj.length;i++) {" + "if (!cq5forms_regcheck(obj[i].value, "); out.write(regexp); out.write(")) {" + "cq5forms_showMsg('"); out.write(FormsHelper.getFormId(request)); out.write("','"); out.write(desc.getName()); out.write("','"); out.write(getConstraintMessage(desc, request)); out.write("', i); return false;}}} else {" + "if (!cq5forms_regcheck(obj.value, "); out.write(regexp); out.write(")) {" + "cq5forms_showMsg('"); out.write(StringEscapeUtils.escapeEcmaScript(FormsHelper.getFormId(request))); out.write("','"); out.write(StringEscapeUtils.escapeEcmaScript(desc.getName())); out.write("','"); out.write(StringEscapeUtils.escapeEcmaScript(getConstraintMessage(desc, request))); out.write("'); return false;}}}"); }