List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:com.bstek.dorado.view.widget.ComponentReferencePropertyOutputter.java
public void output(Object object, OutputContext context) throws Exception { Writer writer = context.getWriter(); JsonBuilder jsonBuilder = context.getJsonBuilder(); String id = String.valueOf(object); String[] ids = StringUtils.split(id, ','); if (ids.length > 1) { jsonBuilder.array();// w w w . j a v a 2 s .c o m for (int i = 0; i < ids.length; i++) { jsonBuilder.beginValue(); writer.append("view.getComponentReference(\""); writer.append(ids[i]); writer.append("\")"); jsonBuilder.endValue(); } jsonBuilder.endArray(); } else { jsonBuilder.beginValue(); writer.append("view.getComponentReference(\""); writer.append(id); writer.append("\")"); jsonBuilder.endValue(); } }
From source file:org.sonar.dotnet.tools.stylecop.MsBuildFileGenerator.java
private void generateProjectList(Writer writer, List<VisualStudioProject> vsProjects) throws IOException { for (VisualStudioProject project : vsProjects) { if (project.getProjectFile() == null) { // this is a Web project without ".csproj" file, we need to add a wildcard pattern writer.append(" <CSFile Include=\""); StringEscapeUtils.escapeXml(writer, project.getDirectory().getAbsolutePath() + "\\**\\*.cs"); writer.append("\"></CSFile>\n"); } else {/*from ww w . j a va 2 s. c om*/ writer.append(" <Project Include=\""); StringEscapeUtils.escapeXml(writer, project.getProjectFile().getAbsolutePath()); writer.append("\"></Project>\n"); } } }
From source file:org.tap4j.producer.TapProducerImpl.java
public void dump(TestSet testSet, Writer writer) throws TapProducerException { String tapStream = null;// w w w . j a v a 2 s. c om try { tapStream = this.dump(testSet); } catch (RepresenterException re) { throw new TapProducerException("Failed to dump Test Set to writer: " + re.getMessage(), re); } try { writer.append(tapStream); } catch (IOException e) { throw new TapProducerException("Failed to dump TAP Stream: " + e.getMessage(), e); } }
From source file:annis.visualizers.iframe.dependency.VakyarthaDependencyTree.java
private void println(String s, int indent, Writer writer) throws IOException { for (int i = 0; i < indent; i++) { writer.append("\t"); }/*from w w w .j a v a2s. co m*/ writer.append(s); writer.append("\n"); }
From source file:org.jamwiki.migrate.MediaWikiXmlExporter.java
/** * *//*from w w w . j ava 2 s .com*/ private void writeSiteInfo(Writer writer, String virtualWikiName) throws DataAccessException, IOException { VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName); writer.append("\n<siteinfo>"); String sitename = virtualWiki.getSiteName(); writer.append('\n'); XMLUtil.buildTag(writer, "sitename", sitename, true); String base = this.retrieveBaseUrl(); writer.append('\n'); XMLUtil.buildTag(writer, "base", base, true); String generator = "JAMWiki " + WikiVersion.CURRENT_WIKI_VERSION; writer.append('\n'); XMLUtil.buildTag(writer, "generator", generator, true); /* Cannot have two titles differing only by case of first letter. Default behavior through 1.5, $wgCapitalLinks = true <enumeration value="first-letter" /> Complete title is case-sensitive. Behavior when $wgCapitalLinks = false <enumeration value="case-sensitive" /> Cannot have two titles differing only by case. Not yet implemented as of MediaWiki 1.5 <enumeration value="case-insensitive" /> */ writer.append('\n'); XMLUtil.buildTag(writer, "case", "case-sensitive", true); writer.append("\n<namespaces>"); Map<String, String> attributes = new LinkedHashMap<String, String>(); List<Namespace> namespaces = WikiBase.getDataHandler().lookupNamespaces(); for (Namespace namespace : namespaces) { attributes.put("key", Integer.toString(namespace.getId())); writer.append('\n'); XMLUtil.buildTag(writer, "namespace", namespace.getLabel(virtualWikiName), attributes, true); } writer.append("\n</namespaces>"); writer.append("\n</siteinfo>"); }
From source file:com.googlecode.osde.internal.profiling.Profile.java
private void writeNewPrefs(Map<String, String> prefs) { Writer writer = null; try {//from ww w. j a v a 2s. c o m writer = new FileWriter(userPreferenceFile); for (Map.Entry<String, String> entry : prefs.entrySet()) { writer.append(String.format("user_pref(\"%s\", %s);\n", entry.getKey(), entry.getValue())); } } catch (IOException e) { throw new ProfilingException(e); } finally { closeQuietly(writer); } }
From source file:com.github.rwitzel.streamflyer.core.ModifiableReaderUnitTest.java
private void assertModificationByWriter(String input, String expectedOutput, long positionForModification, Change modificationToApply) throws Exception { // setup: create modifier and reader StringWriter stringWriter = new StringWriter(); Writer writer = createWriter(stringWriter, positionForModification, modificationToApply); // read the stream into an output stream for (int index = 0; index < input.length(); index++) { writer.append(input.charAt(index)); }// w w w . j av a 2s. co m writer.flush(); writer.close(); String foundOutput = stringWriter.toString(); // compare the expected result with the found result assertEquals(expectedOutput, foundOutput); }
From source file:uk.ac.ox.webauth.PrivateKeyManager.java
/** * Saves all the keys we know about to a keyring. * @param keyring The path to save the keys to. *//*from w w w . j ava 2 s .c o m*/ private synchronized void saveKeys(File keyring) throws IOException { Writer out = null; try { out = new BufferedWriter(new FileWriter(keyring)); out.append("v=").append(Integer.toString(v)).append(";"); out.append("n=").append(Integer.toString(keys.size())).append(";"); List<WebauthKey> sortedKeys = new ArrayList<WebauthKey>(keys); Collections.sort(sortedKeys, new Comparator<WebauthKey>() { public int compare(WebauthKey key1, WebauthKey key2) { return key1.kn() - key2.kn(); } }); for (int i = 0; i < sortedKeys.size(); i++) { WebauthKey key = sortedKeys.get(i); out.append("ct").append(Integer.toString(i)).append("=").append(Integer.toString(key.ct())) .append(";"); out.append("va").append(Integer.toString(i)).append("=").append(Integer.toString(key.va())) .append(";"); out.append("kt").append(Integer.toString(i)).append("=").append(Integer.toString(key.kt())) .append(";"); out.append("kd").append(Integer.toString(i)).append("=").append(key.kd()).append(";"); } } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); } } } if (logger.debug()) { logger.debug("Saved " + keys.size() + " keys to the keyring: " + keyring.getPath() + "."); } }
From source file:com.workfront.api.StreamClient.java
private void addFileToRequest(String boundary, Writer out, OutputStream binaryStream, File file) throws IOException { out.append("--" + boundary).append(NEW_LINE); out.append("Content-Disposition: form-data; name=\"uploadedFile\"; filename=\"" + file.getName() + "\"") .append(NEW_LINE);//from w w w. ja v a2 s .co m out.append("Content-Type: " + URLConnection.guessContentTypeFromName(file.getName())).append(NEW_LINE); out.append("Content-Transfer-Encoding: binary").append(NEW_LINE).append(NEW_LINE); out.flush(); FileInputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int bytesRead = -1; while ((bytesRead = inputStream.read(buffer)) != -1) { binaryStream.write(buffer, 0, bytesRead); } binaryStream.flush(); inputStream.close(); out.append(NEW_LINE); out.flush(); out.append("--").append(boundary).append("--").append(NEW_LINE); }
From source file:org.apache.shindig.protocol.JsonRpcServlet.java
protected void dispatch(JSONObject request, Map<String, FormDataItem> formItems, HttpServletRequest servletRequest, HttpServletResponse servletResponse, SecurityToken token, String callback) throws JSONException, IOException { String key = null;//w ww. j a va2s . co m if (request.has("id")) { key = request.getString("id"); } // getRpcHandler never returns null Future<?> future = getHandler(request, servletRequest).execute(formItems, token, jsonConverter); // Resolve each Future into a response. // TODO: should use shared deadline across each request ResponseItem response = getResponseItem(future); Object result = getJSONResponse(key, response); // Generate the output Writer writer = servletResponse.getWriter(); if (callback != null) writer.append(callback).append('('); jsonConverter.append(writer, result); if (callback != null) writer.append(");\n"); }