List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:com.eufar.asmm.server.DownloadFunction.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("DownloadFunction - the function started"); ServletContext context = getServletConfig().getServletContext(); request.setCharacterEncoding("UTF-8"); String dir = context.getRealPath("/tmp"); ;/* w w w .ja v a2 s . c o m*/ String filename = ""; File fileDir = new File(dir); try { System.out.println("DownloadFunction - create the file on server"); filename = request.getParameterValues("filename")[0]; String xmltree = request.getParameterValues("xmltree")[0]; // format xml code to pretty xml code Document doc = DocumentHelper.parseText(xmltree); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent(true); format.setIndentSize(4); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8")); out.append(sw.toString()); out.flush(); out.close(); } catch (Exception ex) { System.out.println("ERROR during rendering: " + ex); } try { System.out.println("DownloadFunction - send file to user"); ServletOutputStream out = response.getOutputStream(); File file = new File(dir + "/" + filename); String mimetype = context.getMimeType(filename); response.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Pragma", "private"); response.setHeader("Cache-Control", "private, must-revalidate"); DataInputStream in = new DataInputStream(new FileInputStream(file)); int length; while ((in != null) && ((length = in.read(bbuf)) != -1)) { out.write(bbuf, 0, length); } in.close(); out.flush(); out.close(); FileUtils.cleanDirectory(fileDir); } catch (Exception ex) { System.out.println("ERROR during downloading: " + ex); } System.out.println("DownloadFunction - file ready to be donwloaded"); }
From source file:org.sonar.plugins.checkstyle.CheckstyleProfileExporter.java
private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException { writer.append("<module name=\"TreeWalker\">"); writer.append("<module name=\"FileContentsHolder\"/> "); for (String configKey : activeRulesByConfigKey.keySet()) { if (isInTreeWalker(configKey)) { List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey); for (ActiveRule activeRule : activeRules) { appendModule(writer, activeRule); }//from ww w. ja va 2 s. c o m } } writer.append("</module>"); }
From source file:org.sonar.api.profiles.XMLProfileSerializer.java
private void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException { if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) { writer.append("<parameters>"); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { appendRuleParameter(writer, activeRuleParam); }//from ww w .j av a2 s .c o m writer.append("</parameters>"); } }
From source file:com.echosource.ada.rules.AdaProfileExporter.java
private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException { writer.append("<module name=\"TreeWalker\">"); writer.append("<module name=\"FileContentsHolder\"/> "); for (String configKey : activeRulesByConfigKey.keySet()) { if (isInTreeWalker(configKey)) { List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey); for (ActiveRule activeRule : activeRules) { appendModule(writer, activeRule, activeRules.size() > 1); }//from w w w .j a v a 2 s .c o m } } writer.append("</module>"); }
From source file:it.delli.mwebc.ui.impl.ApplicationImpl.java
public void printJavaScriptStream(Writer out) { try {// w ww . ja v a 2 s. com out.append("<cmds>"); for (Iterator<String> javaScriptIterator = getJavaScriptStatementIterator(); javaScriptIterator .hasNext();) { String command = javaScriptIterator.next(); out.append("<cmd><![CDATA[" + command + "]]></cmd>\n"); } clearJavaScriptStatementStream(); if (pageForward != null) { out.append("<forward><![CDATA[" + httpServletRequest.getContextPath() + "/" + pageForward + ".mwc ]]></forward>\n"); pageForward = null; } if (pageOpen != null) { out.append("<open><![CDATA[" + httpServletRequest.getContextPath() + "/" + pageOpen + ".mwc ]]></open>\n"); pageOpen = null; } out.append("</cmds>"); } catch (IOException e) { log.error("Exception in rendering Application controller", e); } }
From source file:org.sonar.dotnet.tools.stylecop.MsBuildFileGenerator.java
protected void generateContent(Writer writer, File styleCopRuleFile, File reportFile, List<VisualStudioProject> vsProjects) throws IOException { writer.append("<?xml version=\"1.0\" ?>\n"); writer.append(//from ww w . ja v a2 s .co m "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" DefaultTargets=\"StyleCopLaunch\" ToolsVersion=\"3.5\">\n"); writer.append(" <PropertyGroup>\n"); writer.append(" <ProjectRoot>"); StringEscapeUtils.escapeXml(writer, solution.getSolutionDir().getAbsolutePath()); writer.append("</ProjectRoot>\n"); writer.append(" <StyleCopRoot>"); StringEscapeUtils.escapeXml(writer, styleCopFolder.getAbsolutePath()); writer.append("</StyleCopRoot>\n"); writer.append(" </PropertyGroup>\n"); writer.append( " <UsingTask TaskName=\"StyleCopTask\" AssemblyFile=\"$(StyleCopRoot)\\Microsoft.StyleCop.dll\"></UsingTask>\n"); writer.append(" <ItemGroup>\n"); generateProjectList(writer, vsProjects); writer.append(" </ItemGroup>\n"); writer.append(" <Target Name=\"StyleCopLaunch\">\n"); writer.append(" <CreateItem Include=\"%(Project.RootDir)%(Project.Directory)**\\*.cs\">\n"); writer.append(" <Output ItemName=\"SourceAnalysisFiles\" TaskParameter=\"Include\"></Output>\n"); writer.append(" </CreateItem>\n"); writer.append(" <StyleCopTask MaxViolationCount=\"-1\" OverrideSettingsFile=\""); StringEscapeUtils.escapeXml(writer, styleCopRuleFile.getAbsolutePath()); writer.append("\"\n OutputFile=\""); StringEscapeUtils.escapeXml(writer, reportFile.getAbsolutePath()); writer.append("\"\n TreatErrorsAsWarnings=\"true\" ForceFullAnalysis=\"true\"\n"); writer.append(" SourceFiles=\"@(SourceAnalysisFiles);@(CSFile)\"\n"); writer.append(" ProjectFullPath=\""); StringEscapeUtils.escapeXml(writer, solution.getSolutionFile().getAbsolutePath()); writer.append("\"></StyleCopTask>\n"); writer.append(" </Target>\n"); writer.append("</Project>"); }
From source file:org.squashtest.tm.tools.annotation.processor.DynamicComponentProcessor.java
private void outputSpringContextFile(Writer writer) throws IOException { writer.append(FILE_HEADER); for (Element manager : dynamicComponents) { // messager.printMessage(Kind.NOTE, // "INFO Processing @" + annotationClass().getSimpleName() + ' ' + manager.getSimpleName(), manager); String beanDefinition = buildBeanDefinition(manager); writer.append(beanDefinition);//from w w w . j a v a 2s . com } writer.append(FILE_FOOTER); }
From source file:org.sonar.plugins.csharp.stylecop.profiles.StyleCopProfileExporter.java
private void printRuleFile(Writer writer, Map<String, List<StyleCopRule>> rulesByAnalyzer, String analyzerId) throws IOException { writer.append(" <Analyzer AnalyzerId=\""); StringEscapeUtils.escapeXml(writer, analyzerId); writer.append("\">\n"); writer.append(" <Rules>\n"); for (StyleCopRule styleCopRule : rulesByAnalyzer.get(analyzerId)) { printRule(writer, styleCopRule); }/*from w w w. ja v a2 s .c o m*/ writer.append(" </Rules>\n"); writer.append(" </Analyzer>\n"); }
From source file:com.apress.progwt.server.web.controllers.GearsLocalServerManifestController.java
/** * { "betaManifestVersion": 1, "version": "my_version_string", * "entries": [ { "url": "go_offline.html"}, { "url": * "go_offline.js"}, { "url": "gears_init.js"} ] } * //from w w w. ja va 2 s . com * @param output * @throws IOException * @throws JSONException */ @RequestMapping(method = RequestMethod.GET) public void forumsHandler(Writer output) throws IOException, JSONException { if (manifest == null) { manifest = createManifest(); } output.append(manifest); output.close(); }
From source file:com.echosource.ada.rules.AdaProfileExporter.java
private void appendModuleProperty(Writer writer, String propertyKey, String propertyValue) throws IOException { if (StringUtils.isNotBlank(propertyValue)) { writer.append("<property name=\""); StringEscapeUtils.escapeXml(writer, propertyKey); writer.append("\" value=\""); StringEscapeUtils.escapeXml(writer, propertyValue); writer.append("\"/>"); }/*from ww w.j a v a 2 s . com*/ }