List of usage examples for java.io CharArrayWriter toString
public String toString()
From source file:org.grails.plugin.freemarker.TagLibToDirectiveAndFunction.java
@SuppressWarnings("serial") @Override/* w w w. j a va2s .c o m*/ public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (log.isDebugEnabled()) { log.debug("exec(): @" + namespace + "." + tagName); } try { CharArrayWriter writer = new CharArrayWriter(); tagInstance.invokeMethod("pushOut", writer); Object args = null; Object body = null; if (arguments != null) { if (arguments.size() > 0) { args = arguments.get(0); } if (arguments.size() > 1) { body = arguments.get(1); } } Object result = null; args = args != null ? unwrapParams((TemplateHashModelEx) args, Boolean.TRUE) : unwrapParams(Collections.EMPTY_MAP, Boolean.TRUE); if (log.isDebugEnabled()) { log.debug("exec(): args " + args); log.debug("exec(): body " + body); } if (tagInstance.getMaximumNumberOfParameters() == 1) { result = tagInstance.call(args); } else { Closure bodyClosure = EMPTY_BODY; if (body != null || hasReturnValue) { final Object fBody = body; bodyClosure = new Closure(this) { @SuppressWarnings("unused") public Object doCall(Object it) throws IOException, TemplateException { return fBody; } }; } result = tagInstance.call(new Object[] { args, bodyClosure }); if (result == null) { // writer.flush(); result = writer.toString(); } } return result; } catch (RuntimeException e) { throw new TemplateModelException(e); } finally { tagInstance.invokeMethod("popOut", null); } }
From source file:com.snowplowanalytics.snowplow.collectors.clojure.SnowplowAccessLogValve.java
/** * Log the specified message to the log file, switching files if the date * has changed since the previous log call. * * @param message Message to be logged//from w w w. j a v a2 s. c o m */ @Override public void log(CharArrayWriter message) { rotate(); /* In case something external rotated the file instead */ if (checkExists) { synchronized (this) { if (currentLogFile != null && !currentLogFile.exists()) { try { close(false); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); log.info(sm.getString("accessLogValve.closeFail"), e); } /* Make sure date is correct */ dateStamp = fileDateFormatter.format(new Date(System.currentTimeMillis())); open(); } } } // Log this message try { synchronized (this) { if (writer != null) { message.writeTo(writer); writer.println(""); if (!buffered) { writer.flush(); } } } } catch (IOException ioe) { log.warn(sm.getString("accessLogValve.writeFail", message.toString()), ioe); } }
From source file:com.aoindustries.website.signup.ServerConfirmationCompletedActionHelper.java
/** * Sends a summary email and returns <code>true</code> if successful. *//* w ww . j a v a 2 s .c o m*/ private static boolean sendSummaryEmail(ActionServlet servlet, HttpServletRequest request, String pkey, String statusKey, String recipient, SiteSettings siteSettings, PackageDefinition packageDefinition, SignupCustomizeServerForm signupCustomizeServerForm, SignupCustomizeManagementForm signupCustomizeManagementForm, SignupBusinessForm signupBusinessForm, SignupTechnicalForm signupTechnicalForm, SignupBillingInformationForm signupBillingInformationForm) { try { Locale userLocale = ThreadLocale.get(); // Find the locale and related resource bundles String charset = Skin.getCharacterSet(userLocale); // Generate the email contents CharArrayWriter cout = new CharArrayWriter(); ChainWriter emailOut = new ChainWriter(cout); String htmlLang = getHtmlLang(userLocale); emailOut.print( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\""); if (htmlLang != null) emailOut.print(" lang=\"").print(htmlLang).print("\" xml:lang=\"").print(htmlLang).print('"'); emailOut.print(">\n" + "<head>\n" + " <meta http-equiv='Content-Type' content='text/html; charset=") .print(charset).print("' />\n"); // Embed the text-only style sheet InputStream cssIn = servlet.getServletContext().getResourceAsStream("/textskin/global.css"); if (cssIn != null) { try { emailOut.print(" <style type=\"text/css\">\n" + " /* <![CDATA[ */\n"); Reader cssReader = new InputStreamReader(cssIn); try { char[] buff = new char[4096]; int ret; while ((ret = cssReader.read(buff, 0, 4096)) != -1) emailOut.write(buff, 0, ret); } finally { cssIn.close(); } emailOut.print(" /* ]]> */\n" + " </style>\n"); } finally { cssIn.close(); } } else { servlet.log("Warning: Unable to find resource: /global/textskin.css"); } emailOut.print( "</head>\n" + "<body>\n" + "<table style='border:0px' cellpadding=\"0\" cellspacing=\"0\">\n" + " <tr><td style='white-space:nowrap' colspan=\"3\">\n" + " ") .print(accessor.getMessage(statusKey, pkey)).print("<br />\n" + " <br />\n" + " ") .print(accessor.getMessage("serverConfirmationCompleted.belowIsSummary")) .print("<br />\n" + " <hr />\n" + " </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.selectServer.label")).print("</th></tr>\n"); SignupSelectServerActionHelper.printConfirmation(emailOut, packageDefinition); emailOut.print(" <tr><td colspan=\"3\"> </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.customizeServer.label")).print("</th></tr>\n"); AOServConnector rootConn = siteSettings.getRootAOServConnector(); SignupCustomizeServerActionHelper.printConfirmation(request, emailOut, rootConn, packageDefinition, signupCustomizeServerForm); if (signupCustomizeManagementForm != null) { emailOut.print(" <tr><td colspan=\"3\"> </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.customizeManagement.label")).print("</th></tr>\n"); SignupCustomizeManagementActionHelper.printConfirmation(request, emailOut, rootConn, signupCustomizeManagementForm); } emailOut.print(" <tr><td colspan=\"3\"> </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.businessInfo.label")).print("</th></tr>\n"); SignupBusinessActionHelper.printConfirmation(emailOut, rootConn, signupBusinessForm); emailOut.print(" <tr><td colspan=\"3\"> </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.technicalInfo.label")).print("</th></tr>\n"); SignupTechnicalActionHelper.printConfirmation(emailOut, rootConn, signupTechnicalForm); emailOut.print(" <tr><td colspan=\"3\"> </td></tr>\n" + " <tr><th colspan=\"3\">") .print(accessor.getMessage("steps.billingInformation.label")).print("</th></tr>\n"); SignupBillingInformationActionHelper.printConfirmation(emailOut, signupBillingInformationForm); emailOut.print("</table>\n" + "</body>\n" + "</html>\n"); emailOut.flush(); // Send the email Brand brand = siteSettings.getBrand(); Mailer.sendEmail( HostAddress.valueOf(brand.getSignupEmailAddress().getDomain().getAOServer().getHostname()), "text/html", charset, brand.getSignupEmailAddress().toString(), brand.getSignupEmailDisplay(), Collections.singletonList(recipient), accessor.getMessage("serverConfirmationCompleted.email.subject", pkey), cout.toString()); return true; } catch (RuntimeException err) { servlet.log("Unable to send sign up details to " + recipient, err); return false; } catch (IOException err) { servlet.log("Unable to send sign up details to " + recipient, err); return false; } catch (SQLException err) { servlet.log("Unable to send sign up details to " + recipient, err); return false; } catch (MessagingException err) { servlet.log("Unable to send sign up details to " + recipient, err); return false; } }