List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:azkaban.webapp.servlet.LoginAbstractAzkabanServlet.java
protected void writeResponse(HttpServletResponse resp, String response) throws IOException { Writer writer = resp.getWriter(); writer.append(response); writer.flush();/* w w w .j a v a 2s . co m*/ }
From source file:com.amalto.core.storage.record.ViewSearchResultsWriter.java
private void processValue(Writer out, FieldMetadata fieldMetadata, Object value) throws IOException { if (value == null) { throw new IllegalArgumentException("Not supposed to write null values to XML."); //$NON-NLS-1$ }//from w w w.j a v a 2s .com if (delegator.hide(fieldMetadata)) { out.append(StringUtils.EMPTY); return; } String stringValue; TypeMetadata type = fieldMetadata.getType(); if (fieldMetadata instanceof SimpleTypeFieldMetadata) { type = MetadataUtils.getSuperConcreteType(type); } if (Types.DATE.equals(type.getName())) { synchronized (DateConstant.DATE_FORMAT) { stringValue = (DateConstant.DATE_FORMAT).format(value); } } else if (Types.DATETIME.equals(type.getName())) { synchronized (DateTimeConstant.DATE_FORMAT) { stringValue = (DateTimeConstant.DATE_FORMAT).format(value); } } else if (Types.TIME.equals(type.getName())) { synchronized (TimeConstant.TIME_FORMAT) { stringValue = (TimeConstant.TIME_FORMAT).format(value); } } else if (value instanceof Object[]) { StringBuilder valueAsString = new StringBuilder(); CompoundFieldMetadata compoundFields = (CompoundFieldMetadata) ((ReferenceFieldMetadata) fieldMetadata) .getReferencedField(); int i = 0; for (Object current : ((Object[]) value)) { valueAsString.append('[') .append(StorageMetadataUtils.toString(current, compoundFields.getFields()[i++])) .append(']'); } stringValue = valueAsString.toString(); } else { stringValue = String.valueOf(value); } if (fieldMetadata instanceof ReferenceFieldMetadata) { if (value instanceof DataRecord) { // TODO Replace with MetadataUtils.toString() DataRecord referencedRecord = (DataRecord) value; StringBuilder fkValueAsString = new StringBuilder(); for (FieldMetadata keyField : referencedRecord.getType().getKeyFields()) { fkValueAsString.append('[').append(referencedRecord.get(keyField)).append(']'); } stringValue = fkValueAsString.toString(); } else { if (!stringValue.startsWith("[")) { //$NON-NLS-1$ stringValue = "[" + StorageMetadataUtils.toString(value, //$NON-NLS-1$ ((ReferenceFieldMetadata) fieldMetadata).getReferencedField()) + ']'; } } } if (fieldMetadata instanceof AliasedFieldMetadata && ((AliasedFieldMetadata) fieldMetadata).getAliasedField() instanceof ReferenceFieldMetadata) { if (!stringValue.startsWith("[")) { //$NON-NLS-1$ stringValue = "[" + StorageMetadataUtils.toString(value, //$NON-NLS-1$ ((ReferenceFieldMetadata) ((AliasedFieldMetadata) fieldMetadata).getAliasedField()) .getReferencedField()) + ']'; } } out.append(StringEscapeUtils.escapeXml(stringValue)); }
From source file:com.palantir.stash.disapprove.servlet.DisapprovalServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { final String user = authenticateUser(req, res); if (user == null) { // not logged in, redirect res.sendRedirect(lup.getLoginUri(getUri(req)).toASCIIString()); return;// www .j a v a2 s . c om } final String URL_FORMAT = "BASE_URL/REPO_ID"; final String pathInfo = req.getPathInfo(); final String[] parts = pathInfo.split("/"); if (parts.length != 5) { throw new IllegalArgumentException("The format of the URL is " + URL_FORMAT); } final Integer repoId; final Long prId; try { repoId = Integer.valueOf(parts[3]); prId = Long.valueOf(parts[4]); } catch (NumberFormatException e) { throw new IllegalArgumentException("The format of the URL is " + URL_FORMAT, e); } final PullRequest pr = pullRequestService.getById(repoId, prId); if (pr == null) { throw new IllegalArgumentException("No PR found for repo id " + repoId + " pr id " + prId.toString()); } PullRequestDisapproval prd; DisapprovalConfiguration dc; try { prd = pm.getPullRequestDisapproval(pr); dc = pm.getDisapprovalConfiguration(pr.getToRef().getRepository()); } catch (SQLException e) { throw new ServletException(e); } try { Writer w = res.getWriter(); //res.setContentType("text/html;charset=UTF-8"); res.setContentType("application/json;charset=UTF-8"); w.append(new JSONObject(ImmutableMap.of("disapproval", prd.isDisapproved(), "disapprovedBy", prd.getDisapprovedBy(), "enabledForRepo", dc.isEnabled())).toString()); } finally { res.getWriter().close(); } }
From source file:org.apache.shindig.protocol.JsonRpcServlet.java
protected void dispatchBatch(JSONArray batch, Map<String, FormDataItem> formItems, HttpServletRequest servletRequest, HttpServletResponse servletResponse, SecurityToken token, String callback) throws JSONException, IOException { // Use linked hash map to preserve order List<Future<?>> responses = Lists.newArrayListWithCapacity(batch.length()); // Gather all Futures. We do this up front so that // the first call to get() comes after all futures are created, // which allows for implementations that batch multiple Futures // into single requests. for (int i = 0; i < batch.length(); i++) { JSONObject batchObj = batch.getJSONObject(i); responses.add(getHandler(batchObj, servletRequest).execute(formItems, token, jsonConverter)); }// w ww . ja v a 2 s. com // Resolve each Future into a response. // TODO: should use shared deadline across each request List<Object> result = new ArrayList<Object>(batch.length()); for (int i = 0; i < batch.length(); i++) { JSONObject batchObj = batch.getJSONObject(i); String key = null; if (batchObj.has("id")) { key = batchObj.getString("id"); } result.add(getJSONResponse(key, getResponseItem(responses.get(i)))); } // Generate the output Writer writer = servletResponse.getWriter(); if (callback != null) writer.append(callback).append('('); jsonConverter.append(writer, result); if (callback != null) writer.append(");\n"); }
From source file:org.sonar.plugins.csharp.fxcop.profiles.FxCopProfileExporter.java
private void printIntoWriter(Writer writer, String fileName) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(FxCopProfileExporter.class.getResourceAsStream(fileName))); try {//from w w w . ja v a 2 s.c om String line = reader.readLine(); while (line != null) { writer.append(line); writer.append("\n"); line = reader.readLine(); } reader.close(); } finally { IOUtils.closeQuietly(reader); } }
From source file:org.sonar.plugins.csharp.gendarme.profiles.GendarmeProfileExporter.java
private void appendRuleList(Writer writer, List<ActiveRule> rules) throws IOException { List<String> ruleNames = new ArrayList<String>(); for (ActiveRule activeRule : rules) { String key = activeRule.getConfigKey(); String ruleName = StringUtils.substringBefore(key, "@"); ruleNames.add(ruleName);//from ww w .j av a2 s . c o m } writer.append(StringUtils.join(ruleNames, " | ")); }
From source file:com.bizosys.hsearch.index.DocTeaser.java
public void toXml(Writer pw) throws IOException { if (null == pw) return;// w w w . ja v a 2 s . co m if (null != id) { pw.append('<').append(IOConstants.TEASER_ID).append('>'); pw.append(id); pw.append("</").append(IOConstants.TEASER_ID).append('>'); } if (null != url) { pw.append('<').append(IOConstants.TEASER_URL).append("><![CDATA["); pw.append(url.toString()); pw.append("]]></").append(IOConstants.TEASER_URL).append('>'); } if (null != title) { pw.append('<').append(IOConstants.TEASER_TITLE).append("><![CDATA["); pw.append(title.toString()); pw.append("]]></").append(IOConstants.TEASER_TITLE).append('>'); } if (null != cacheText) { pw.append('<').append(IOConstants.TEASER_CACHE).append("><![CDATA["); pw.append(cacheText.toString()); pw.append("]]></").append(IOConstants.TEASER_CACHE).append('>'); } if (null != preview) { pw.append('<').append(IOConstants.TEASER_PREVIEW).append("><![CDATA["); pw.append(preview); pw.append("]]></").append(IOConstants.TEASER_PREVIEW).append('>'); } }
From source file:org.teavm.tooling.TeaVMTestTool.java
private void escapeString(String string, Writer writer) throws IOException { writer.append('\"'); for (int i = 0; i < string.length(); ++i) { char c = string.charAt(i); switch (c) { case '"': writer.append("\\\""); break; case '\\': writer.append("\\\\"); break; case '\n': writer.append("\\n"); break; case '\r': writer.append("\\r"); break; case '\t': writer.append("\\t"); break; default:/* w w w.j a va2 s . c o m*/ writer.append(c); break; } } writer.append('\"'); }
From source file:org.apache.hadoop.hbase.wal.TestWALSplit.java
public static long appendEntry(Writer writer, TableName table, byte[] region, byte[] row, byte[] family, byte[] qualifier, byte[] value, long seq) throws IOException { LOG.info(Thread.currentThread().getName() + " append"); writer.append(createTestEntry(table, region, row, family, qualifier, value, seq)); LOG.info(Thread.currentThread().getName() + " sync"); writer.sync();//from w ww .jav a2 s . c o m return seq; }
From source file:com.github.rvesse.airline.help.html.HtmlCommandUsageGenerator.java
/** * Outputs additional CSS directly/*from w ww. j a v a2s . c o m*/ * * @param writer * Writer * @throws IOException */ protected void outputAdditionalCss(Writer writer) throws IOException { writer.append(" body { margin: 50px; }\n"); }