List of usage examples for java.io PrintWriter append
public PrintWriter append(char c)
From source file:com.opendoorlogistics.core.utils.strings.Strings.java
public static void writeToFile(String s, File file) { try {// w w w . j a v a2 s . co m PrintWriter out = new PrintWriter(file); out.append(s); out.close(); } catch (Throwable e) { throw new RuntimeException(e); } }
From source file:org.jahia.izpack.ResourcesConverter.java
/** * Performs conversion of the property file into XML language pack. * //from ww w . j a v a 2 s.c o m * @param bundleName * the resource bundle name * @param locale * locale to be used * @param targetFolder * the target folder * @throws FileNotFoundException */ private static void convert(String bundleName, Locale locale, File targetFolder) throws FileNotFoundException { ResourceBundle enBundle = ResourceBundle.getBundle(bundleName, Locale.ENGLISH); ResourceBundle bundle = null; try { bundle = ResourceBundle.getBundle(bundleName, locale); } catch (MissingResourceException e) { bundle = enBundle; } PrintWriter out = new PrintWriter(new File(targetFolder, StringUtils.substringAfterLast(bundleName, ".") + "." + locale.getISO3Language() + ".xml")); Enumeration<String> keyEnum = enBundle.getKeys(); List<String> keys = new LinkedList<String>(); while (keyEnum.hasMoreElements()) { keys.add(keyEnum.nextElement()); } Collections.sort(keys); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<langpack>"); for (String key : keys) { String value = null; try { value = bundle.getString(key); } catch (MissingResourceException e) { try { value = enBundle.getString(key); } catch (MissingResourceException e2) { value = key; } } out.append(" <str id=\"").append(key).append("\" txt=\"").append(StringEscapeUtils.escapeXml(value)) .append("\"/>"); out.println(); } out.println("</langpack>"); out.flush(); out.close(); }
From source file:cz.muni.fi.pb138.callboxesmap.CallboxesServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setCharacterEncoding(CallboxesXMLClass.CHARACTER_ENCODING); PrintWriter writer = resp.getWriter(); writer.append(getJsonCallboxes().toString()); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.AppsList.java
void toDataTableArrays(Collection<RMAppState> requiredAppStates, PrintWriter out) { out.append('['); boolean first = true; for (RMApp app : apps.values()) { if (requiredAppStates != null && !requiredAppStates.contains(app.getState())) { continue; }/*from w w w . j a va2s .c o m*/ AppInfo appInfo = new AppInfo(app, true); String startTime = Times.format(appInfo.getStartTime()); String finishTime = Times.format(appInfo.getFinishTime()); if (first) { first = false; } else { out.append(",\n"); } out.append("[\""); appendSortable(out, appInfo.getAppIdNum()); appendLink(out, appInfo.getAppId(), rc.prefix(), "app", appInfo.getAppId()).append(_SEP) .append(escapeHtml(appInfo.getUser())).append(_SEP) .append(escapeJavaScript(escapeHtml(appInfo.getName()))).append(_SEP) .append(escapeHtml(appInfo.getQueue())).append(_SEP); appendSortable(out, appInfo.getStartTime()).append(startTime).append(_SEP); appendSortable(out, appInfo.getFinishTime()).append(finishTime).append(_SEP).append(appInfo.getState()) .append(_SEP).append(appInfo.getFinalStatus()).append(_SEP); appendProgressBar(out, appInfo.getProgress()).append(_SEP); appendLink(out, appInfo.getTrackingUI(), rc.prefix(), !appInfo.isTrackingUrlReady() ? "#" : appInfo.getTrackingUrlPretty()).append("\"]"); } out.append(']'); }
From source file:org.codice.ddf.status.CpuService.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); writer.append(toJSON()); }
From source file:com.refreshsf.contrib.sling.example.RefreshSfExampleServlet.java
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String clientName = request.getRequestParameter(PARAM_CLIENT_NAME).getString(); String optionSetName = request.getRequestParameter(PARAM_OPTION_SET_NAME).getString(); RefreshSfClient client = refreshSfService.getConfiguredClient(clientName); RefreshSfOptionSet optionSet = refreshSfService.getConfiguredOptionSet(optionSetName); Javascript jsApi = client.getJavascriptApi(); String hardCodedExample = "console.log('hello world');var a = 8+2; if (a > 10) { a++; }"; try {// w ww . j a va2 s .co m Result result = jsApi.uglify(hardCodedExample, optionSet.asJavascriptOptions()); response.getWriter().append(result.getCode()); } catch (RetrofitError error) { PrintWriter writer = response.getWriter(); writer.append("\nurl=" + error.getUrl()).append("\nkind=" + error.getKind().toString()) .append("\nstatus=" + error.getResponse().getStatus()) .append("\nreason=" + error.getResponse().getReason()) .append("\nbody=" + IOUtils.toString(error.getResponse().getBody().in(), "UTF-8")); ErrorResult error1 = (ErrorResult) error.getBodyAs(ErrorResult.class); writer.append("\n").append("\nmsg=" + error1.getMsg()).append("\ndefs=" + error1.getDefs().toString()); } }
From source file:org.codice.ddf.status.DiskService.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); writer.append(toJSON()); }
From source file:dk.dbc.DevelMain.java
@Override public void run(OaiSetMatcherConfiguration config, Environment env) throws Exception { super.run(config, env); env.admin().addTask(new Task("terminate") { @Override//from ww w .j ava 2s . c o m public void execute(ImmutableMultimap<String, String> im, PrintWriter writer) throws Exception { writer.append("EXITTING\n"); writer.close(); new Thread() { @Override @SuppressFBWarnings(value = "DM_EXIT", justification = "It's intentional that the system should exit on a 'terminate' call") public void run() { log.info("EXITTING"); System.exit(0); } }.start(); } }); }
From source file:org.sakaiproject.nakamura.doc.GeneralDocumentationServlet.java
private void sendIndex(SlingHttpServletResponse response) throws IOException { PrintWriter writer = response.getWriter(); writer.append(DocumentationConstants.HTML_HEADER); writer.append("<h1>List of Services</h1>"); writer.append("<ul>"); Map<String, ServletDocumentation> m = servletDocumentationRegistry.getServletDocumentation(); List<ServletDocumentation> o = new ArrayList<ServletDocumentation>(m.values()); Collections.sort(o);/* ww w . java 2 s . c om*/ for (ServletDocumentation k : o) { if (k.isDocumentationServlet()) { String key = k.getKey(); if (key != null) { writer.append("<li><a href=\""); writer.append(k.getUrl()); writer.append("\">"); writer.append(k.getServiceDocumentationName()); writer.append("</a><p>"); writer.append(k.getShortDescription()); writer.append("</p></li>"); } } } writer.append("</ul>"); writer.append(DocumentationConstants.HTML_FOOTER); }
From source file:com.brokenmodel.swats.RouterServlet.java
private void handleRequest(HttpServletRequest request, HttpServletResponse response, ControllerRequest.Type type) { try {/* w ww . j av a 2 s.com*/ URL rootURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + request.getServletPath()); String appRoot = rootURL.getFile(); String htmlRoot = request.getContextPath(); MatchedRoute matchedRoute = controllers.matchRoute(request.getPathInfo()); ControllerRequest controllerRequest = new ControllerRequest(request, response, appRoot, htmlRoot, matchedRoute.getUrlParams(), type, handleMultipart(request), getDataSource()); AbstractController controller = matchedRoute.getController(); controller.doRequest(controllerRequest); } catch (Throwable t) { log(t); try { // only will work if output stream has not been opened PrintWriter pw = new PrintWriter(response.getWriter()); pw.append("<pre>"); pw.append("We're sorry - an error has occurred:\n\n"); t.printStackTrace(pw); pw.append("</pre>"); } catch (Throwable t2) { } } }