List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:edu.umn.msi.tropix.common.io.IOUtilsImpl.java
public Writer append(@Nonnull final Writer writer, @Nonnull final CharSequence charSequence) { try {//from www.j a va 2 s . c o m return writer.append(charSequence); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:com.bstek.dorado.view.resolver.PageHeaderOutputter.java
public void output(Object object, OutputContext context) throws Exception { DoradoContext doradoContext = DoradoContext.getCurrent(); View view = (View) object; String skin = skinResolver.determineSkin(doradoContext, view); doradoContext.setAttribute("view.skin", skin); int currentClientType = VariantUtils.toInt(doradoContext.getAttribute(ClientType.CURRENT_CLIENT_TYPE_KEY)); if (currentClientType == 0) { currentClientType = ClientType.DESKTOP; }/*from w ww . ja v a 2 s .c o m*/ Writer writer = context.getWriter(); writer.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=") .append(Constants.DEFAULT_CHARSET).append("\" />\n"); if (StringUtils.isNotEmpty(view.getTitle())) { writer.append("<title>").append(StringEscapeUtils.escapeHtml(view.getTitle())).append("</title>\n"); } Locale locale = localeResolver.resolveLocale(); String contextPath = Configure.getString("web.contextPath"); if (StringUtils.isEmpty(contextPath)) { contextPath = DoradoContext.getAttachedRequest().getContextPath(); } writer.append("<script language=\"javascript\" type=\"text/javascript\" charset=\"UTF-8\" src=\"") .append(contextPath).append("/dorado/client/boot.dpkg?clientType=") .append(ClientType.toString(currentClientType)).append("&skin=").append(skin) .append("&cacheBuster=") .append(CacheBusterUtils.getCacheBuster((locale != null) ? locale.toString() : null)) .append("\"></script>\n").append("<script language=\"javascript\" type=\"text/javascript\">\n"); writer.append("window.$setting={\n"); for (ClientSettingsOutputter clientSettingsOutputter : clientSettingsOutputters) { clientSettingsOutputter.output(writer); } writer.append("\n};\n"); writer.append("$import(\"").append(getBasePackageNames(doradoContext, currentClientType, skin)) .append("\");\n</script>\n").append("<script language=\"javascript\" type=\"text/javascript\">\n"); topViewOutputter.output(view, context); writer.append("</script>\n"); Set<Object> javaScriptContents = context.getJavaScriptContents(); if (javaScriptContents != null && !javaScriptContents.isEmpty()) { writer.append("<script language=\"javascript\" type=\"text/javascript\">\n"); for (Object content : javaScriptContents) { if (content instanceof JavaScriptContent && !((JavaScriptContent) content).getIsController()) { javaScriptResourceManager.outputContent(context, content); } writer.append('\n'); } writer.append("</script>\n"); } Set<Object> styleSheetContents = context.getStyleSheetContents(); if (styleSheetContents != null && !styleSheetContents.isEmpty()) { writer.append("<style type=\"text/css\">\n"); for (Object content : styleSheetContents) { styleSheetResourceManager.outputContent(context, content); writer.append('\n'); } writer.append("</style>\n"); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratAnnotationDocument.java
private void write(Writer aWriter, BratAnnotation aAnno) throws IOException { aWriter.append(aAnno.toString()); aWriter.append('\n'); for (BratAttribute attr : aAnno.getAttributes()) { aWriter.append(attr.toString()); aWriter.append('\n'); }/*from w w w . java 2s .com*/ }
From source file:org.craftercms.cstudio.alfresco.dm.webscript.content.GetContentWebScript.java
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException { // get parameters and check for mandatory parameters String site = req.getParameter(CStudioWebScriptConstants.PARAM_SITE); WebScriptUtils.checkMandatoryParameter(CStudioWebScriptConstants.PARAM_SITE, site); String path = req.getParameter(CStudioWebScriptConstants.PARAM_PATH); WebScriptUtils.checkMandatoryParameter(CStudioWebScriptConstants.PARAM_PATH, path); String edit = req.getParameter(CStudioWebScriptConstants.PARAM_EDIT); String draft = req.getParameter(CStudioWebScriptConstants.PARAM_DRAFT); String changeTemplate = req.getParameter(CStudioWebScriptConstants.PARAM_CHANGETEMPLATE); Boolean isDraft = Boolean.valueOf(draft); Boolean isChangeTemplate = Boolean.valueOf(changeTemplate); if (logger.isDebugEnabled()) { logger.debug("dm content requested by site: " + site + " and path: " + path + ", edit: " + edit); }//from ww w . j a va2s . co m boolean isEdit = (StringUtils.isEmpty(edit)) ? false : edit.equalsIgnoreCase("true"); String[] levels = path.split("/"); // if no file name in the path, throw an error if (levels.length < 1 && StringUtils.isEmpty(levels[levels.length - 1])) { throw new WebScriptException("Failed to get content. No file name specified in the path: " + path); } else { String fileName = levels[levels.length - 1]; InputStream input = null; OutputStream output = null; try { /* Disable DRAFT repo Dejan 29.03.2012 */ /* if (isDraft) { try { input = _dmContentService.getContentFromDraft(site, path, isEdit, !isChangeTemplate); } catch (ContentNotFoundException e) { input = _dmContentService.getContent(site, path, isEdit, !isChangeTemplate); } } else { input = _dmContentService.getContent(site, path, isEdit, !isChangeTemplate); } */ PersistenceManagerService persistenceManagerService = getServicesManager() .getService(PersistenceManagerService.class); DmContentService dmContentService = getServicesManager().getService(DmContentService.class); ObjectStateService objectStateService = getServicesManager().getService(ObjectStateService.class); ServicesConfig servicesConfig = getServicesManager().getService(ServicesConfig.class); String fullPath = servicesConfig.getRepositoryRootPath(site) + path; if (isEdit) { persistenceManagerService.setSystemProcessing(fullPath, true); } input = dmContentService.getContent(site, path, isEdit, !isChangeTemplate); if (isEdit) { persistenceManagerService.transition(fullPath, ObjectStateService.TransitionEvent.EDIT); persistenceManagerService.setSystemProcessing(fullPath, false); } /***************************************/ String[] values = path.split("\\."); String fileType = values[values.length - 1]; res.setHeader("Content-Type", "application/" + fileType.toLowerCase()); res.setHeader("Content-Disposition", "inline;filename=\"" + fileName + "\""); res.setHeader("Cache-Control", "max-age=0"); res.setHeader("Pragma", "public"); // write the file if (logger.isDebugEnabled()) { logger.debug("content asset found. Transmitting the file."); } output = res.getOutputStream(); byte[] buffer = new byte[CStudioWebScriptConstants.READ_BUFFER_LENGTH]; int read = 0; while ((read = input.read(buffer)) > 0) { output.write(buffer, 0, read); } if (logger.isDebugEnabled()) { logger.debug("file transmission completed."); } } catch (AccessDeniedException e) { res.setStatus(Status.STATUS_CONFLICT); Writer writer = res.getWriter(); writer.append(e.getMessage()); writer.close(); } catch (ContentNotFoundException e) { res.setStatus(Status.STATUS_BAD_REQUEST); Writer writer = res.getWriter(); writer.append("Failed to get content by site: " + site + " and path: " + path); writer.close(); } finally { ContentUtils.release(input, output); } } }
From source file:Main.java
private static void __toColoredHtmlLine(String line, HashMap<String, String> tagColorScheme, Writer writer) throws IOException { if (line.trim().length() == 0) return;// ww w . ja va 2s . c o m line = line.replace("\t", " "); line = line.replace("<", "|<|"); line = line.replace(">", "|>|"); while (true) { int pos = line.indexOf("|<|"); if (pos < 0) break; String tagName = __getNextWord(line, pos + 3); String color = null; if (tagName != null) { color = tagColorScheme.get(tagName); } if (color != null) { line = line.substring(0, pos) + "<span style=\"color: " + color + "; font-weight: bold;\"><" + line.substring(pos + 3); } else { line = line.substring(0, pos) + "<span style=\"color: #808080;\"><" + line.substring(pos + 3); } } line = line.replace("|>|", "></span>"); int n = line.length(); line = line.trim(); n -= line.length(); StringBuilder sb = new StringBuilder(); for (int j = 0; j < n; j++) { sb.append(" "); } writer.append(sb.toString()); writer.append(line); writer.append("<br />\r\n"); }
From source file:org.sonar.plugins.csharp.fxcop.profiles.FxCopProfileExporter.java
private void printRuleFile(Writer writer, Map<String, List<FxCopRule>> rulesByFile, String fileName) throws IOException { writer.append(" <RuleFile AllRulesEnabled=\"False\" Enabled=\"True\" Name=\""); StringEscapeUtils.escapeXml(writer, fileName); writer.append("\">\n"); for (FxCopRule fxCopRule : rulesByFile.get(fileName)) { printRule(writer, fxCopRule);/*from ww w . ja v a 2s .c o m*/ } writer.append(" </RuleFile>\n"); }
From source file:org.optaplanner.benchmark.impl.statistic.SingleStatistic.java
public void writeCsvStatisticFile() { File csvFile = getCsvFile();//from w w w . j a v a 2 s.c o m Writer writer = null; try { writer = new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8"); writer.append(getCsvHeader()).append("\n"); for (StatisticPoint point : getPointList()) { writer.append(point.toCsvLine()).append("\n"); } if (singleBenchmarkResult.isFailure()) { writer.append("Failed\n"); } } catch (IOException e) { throw new IllegalArgumentException("Failed writing csvFile (" + csvFile + ").", e); } finally { IOUtils.closeQuietly(writer); } }
From source file:org.apache.olingo.odata2.core.debug.DebugInfoBody.java
@Override public void appendHtml(final Writer writer) throws IOException { final String body = getContentString(); if (isImage) { writer.append("<img src=\"data:").append(response.getContentHeader()).append(";base64,").append(body) .append("\" />\n"); } else {/*from ww w . j a v a2 s .c o m*/ writer.append("<pre class=\"code").append(isXml ? " xml" : isJson ? " json" : "").append("\">\n") .append(isXml || isJson ? addLinks(ODataDebugResponseWrapper .escapeHtml(isXml ? formatXml(body) : formatJson(body)), isXml) : ODataDebugResponseWrapper.escapeHtml(body)) .append("</pre>\n"); } }
From source file:com.chen.emailcommon.internet.Rfc822Output.java
/** * Write a single attachment and its payload *//*w w w . j av a 2 s . c o m*/ private static void writeOneAttachment(Context context, Writer writer, OutputStream out, Attachment attachment) throws IOException, MessagingException { writeHeader(writer, "Content-Type", attachment.mMimeType + ";\n name=\"" + attachment.mFileName + "\""); writeHeader(writer, "Content-Transfer-Encoding", "base64"); // Most attachments (real files) will send Content-Disposition. The suppression option // is used when sending calendar invites. if ((attachment.mFlags & Attachment.FLAG_ICS_ALTERNATIVE_PART) == 0) { writeHeader(writer, "Content-Disposition", "attachment;" + "\n filename=\"" + attachment.mFileName + "\";" + "\n size=" + Long.toString(attachment.mSize)); } if (attachment.mContentId != null) { writeHeader(writer, "Content-ID", attachment.mContentId); } writer.append("\r\n"); // Set up input stream and write it out via base64 InputStream inStream = null; try { // Use content, if provided; otherwise, use the contentUri if (attachment.mContentBytes != null) { inStream = new ByteArrayInputStream(attachment.mContentBytes); } else { // First try the cached file final String cachedFile = attachment.getCachedFileUri(); if (!TextUtils.isEmpty(cachedFile)) { final Uri cachedFileUri = Uri.parse(cachedFile); try { inStream = context.getContentResolver().openInputStream(cachedFileUri); } catch (FileNotFoundException e) { // Couldn't open the cached file, fall back to the original content uri inStream = null; LogUtils.d(TAG, "Rfc822Output#writeOneAttachment(), failed to load" + "cached file, falling back to: %s", attachment.getContentUri()); } } if (inStream == null) { // try to open the file final Uri fileUri = Uri.parse(attachment.getContentUri()); inStream = context.getContentResolver().openInputStream(fileUri); } } // switch to output stream for base64 text output writer.flush(); Base64OutputStream base64Out = new Base64OutputStream(out, Base64.CRLF | Base64.NO_CLOSE); // copy base64 data and close up IOUtils.copy(inStream, base64Out); base64Out.close(); // The old Base64OutputStream wrote an extra CRLF after // the output. It's not required by the base-64 spec; not // sure if it's required by RFC 822 or not. out.write('\r'); out.write('\n'); out.flush(); } catch (FileNotFoundException fnfe) { // Ignore this - empty file is OK LogUtils.e(TAG, fnfe, "Rfc822Output#writeOneAttachment(), FileNotFoundException" + "when sending attachment"); } catch (IOException ioe) { LogUtils.e(TAG, ioe, "Rfc822Output#writeOneAttachment(), IOException" + "when sending attachment"); throw new MessagingException("Invalid attachment.", ioe); } }
From source file:org.sonar.api.profiles.XMLProfileSerializer.java
private void appendRuleParameter(Writer writer, ActiveRuleParam activeRuleParam) throws IOException { if (StringUtils.isNotBlank(activeRuleParam.getValue())) { writer.append("<parameter><key>"); StringEscapeUtils.escapeXml(writer, activeRuleParam.getKey()); writer.append("</key><value>"); StringEscapeUtils.escapeXml(writer, activeRuleParam.getValue()); writer.append("</value>"); writer.append("</parameter>"); }//w w w. j a va2 s . c o m }