List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:com.jaeksoft.searchlib.util.Debug.java
public void xmlInfo(PrintWriter writer) { writer.print("<debug start=\""); writer.print(dtdf.format(new Date(startTime))); writer.print("\" elapsed=\""); writer.print(elapsedTime);// ww w . j a v a 2s.c o m writer.print("\" info=\""); writer.print(StringEscapeUtils.escapeJava(StringEscapeUtils.escapeXml(info))); writer.print("\" hashCode=\""); writer.print(hc); writer.print("\" class=\""); writer.print(className); writer.print("\">"); if (childrens != null) for (Debug children : childrens) children.xmlInfo(writer); writer.print("</debug>"); }
From source file:com.nesscomputing.httpclient.testsupport.GenericWritingContentHandler.java
@Override public void handle(final String target, final Request request, final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws IOException, ServletException { method = request.getMethod();/*from ww w . ja va2s .c o m*/ InputStream inputStream = request.getInputStream(); postData = IOUtils.toString(inputStream); httpResponse.setContentType(contentType); httpResponse.setStatus(HttpServletResponse.SC_OK); request.setHandled(true); final PrintWriter writer = httpResponse.getWriter(); writer.print(content); writer.flush(); }
From source file:com.att.api.immn.controller.GetMsgController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); final String msgId = request.getParameter("getMsgId"); /* TODO: convert nulls to the '-' character */ JSONObject jresponse = new JSONObject(); try {/* w ww. ja v a 2s .co m*/ final Message msg = srvc.getMessage(msgId); final JSONArray tables = new JSONArray(); final JSONArray values = new JSONArray().put(msg.getMessageId()).put(msg.getFrom()) .put(msg.getRecipients()).put(msg.getText()).put(msg.getTimeStamp()).put(msg.isFavorite()) .put(msg.isUnread()).put(msg.isIncoming()).put(msg.getType()); tables.put(new JSONObject().put("caption", "Message:") .put("headers", new JSONArray().put("Message ID").put("From").put("Recipients").put("Text") .put("Timestamp").put("Favorite").put("Unread").put("Incoming").put("Type")) .put("values", new JSONArray().put(values))); jresponse.put("success", true).put("tables", tables); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
public static void writeAsCSV(InputData data, String fileName) throws IOException { Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing input data as CVS to '" + fileName + "'."); PrintWriter writer = FileUtils.openFileForWriting("CVS", fileName, false); TemplateVector tv = data.templateVector(); if (tv == null) { Logger.getLogger("at.tuwien.ifs.somtoolbox") .info("Template vector not loaded - creating a generic one."); tv = new SOMLibTemplateVector(data.numVectors(), data.dim()); }//from w ww . j a v a 2 s .c o m SOMLibClassInformation classInformation = data.classInformation(); boolean haveClassInfo = classInformation != null; String separator = "\t"; // header: tab-separated label names writer.print(StringUtils.toString(tv.getLabels(), "", "", separator, "\"")); if (haveClassInfo) { // and optionally the class writer.print(separator + "class"); } writer.println(); // data: tab separated, optionally with the class assignment for (int i = 0; i < data.numVectors(); i++) { for (int j = 0; j < data.dim(); j++) { writer.print(data.getValue(i, j)); if (j + 1 < data.dim()) { writer.print(separator); } } if (haveClassInfo) { writer.print(separator + classInformation.getClassName(i)); } writer.println(); } writer.close(); }
From source file:com.att.api.immn.controller.UpdateMsgController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); final String readflag = request.getParameter("updateStatus"); final String msgIdStr = request.getParameter("updateMsgId"); String[] msgIds = msgIdStr.split(","); final Boolean isUnread = readflag.equals("Read") ? false : true; IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); JSONObject jresponse = new JSONObject(); try {/*from w w w . j a va2s .com*/ if (msgIds.length > 1) { DeltaChange[] changes = new DeltaChange[msgIds.length]; for (int i = 0; i < msgIds.length; ++i) { DeltaChange dc = new DeltaChange(msgIds[i], null, isUnread); changes[i] = dc; } srvc.updateMessages(changes); } else { srvc.updateMessage(msgIds[0], isUnread, null); } jresponse.put("success", true).put("text", "Message(s) Updated"); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:com.att.api.immn.controller.GetSubscriptionController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); JSONObject jresponse = new JSONObject(); try {//from w w w . jav a2s . co m if (session.getAttribute("subscriptionId") == null) { throw new RESTException("You must first create a subscription."); } final OAuthToken token = (OAuthToken) session.getAttribute("token"); final String channelId = appConfig.getProperty("channelId"); final String subscriptionId = (String) session.getAttribute("subscriptionId"); final String fqdn = appConfig.getApiFQDN(); final WebhooksService srvc = new WebhooksService(fqdn, token); GetSubscriptionResponse getResponse = srvc.getNotificationSubscriptionDetails(channelId, subscriptionId); JSONArray jheaders = new JSONArray().put("Subscription Id").put("Expires In").put("Queues") .put("Callback Data"); JSONArray jvalues = new JSONArray().put(getResponse.getSubscription().getSubscriptionId()) .put(getResponse.getSubscription().getExpiresIn()) .put(getResponse.getSubscription().getEvents()) .put(getResponse.getSubscription().getCallbackData()); JSONObject jtable = new JSONObject().put("caption", "Subscription Details").put("headers", jheaders) .put("values", new JSONArray().put(jvalues)); JSONArray jtables = new JSONArray().put(jtable); jresponse.put("success", true).put("tables", jtables); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:com.att.api.speech.controller.TextToSpeechController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final JSONObject jresponse = new JSONObject(); try {/*w w w .ja va 2 s .c o m*/ final OAuthToken token = this.getFileToken(); final TtsService srvc = new TtsService(appConfig.getApiFQDN(), token); final String contentType = request.getParameter("contentType"); final String plaintext = request.getParameter("plaintext"); final String ssml = request.getParameter("ssml"); final String xArg = request.getParameter("x_arg"); String speechText = null; if (contentType.equals("text/plain")) { speechText = plaintext; if (speechText.length() > 250) { throw new Exception("Character limited of 250 reached"); } } else { speechText = ssml; } final byte[] wavBytes = srvc.sendRequest(contentType, speechText, xArg); JSONObject jaudio = new JSONObject().put("type", "audio/wav").put("base64", new String(Base64.encodeBase64(wavBytes))); jresponse.put("success", true).put("audio", jaudio); } catch (Exception e) { jresponse.put("success", false).put("text", e.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:forge.card.CardScriptInfo.java
public boolean trySetText(String text0) { if (file == null) { return false; }/*from w ww .j av a2s. c o m*/ try { PrintWriter p = new PrintWriter(file); p.print(text0); p.close(); text = text0; return true; } catch (final Exception ex) { System.err.println("Problem writing file - " + file); ex.printStackTrace(); return false; } }
From source file:com.att.api.immn.controller.SendMsgController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); final String addr = request.getParameter("address"); final String[] addrs = addr.split(","); for (int i = 0; i < addrs.length; ++i) addrs[i] = addrs[i].trim();/*w w w .j a va 2 s. c o m*/ final String msg = request.getParameter("sendMsgInput"); final String subject = request.getParameter("sendSubjectInput"); final boolean group = request.getParameter("groupCheckbox") != null; // TODO: handle attachments IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); JSONObject jresponse = new JSONObject(); try { SendResponse sendResponse = null; if (!subject.isEmpty() || group) { sendResponse = srvc.sendMessage(addrs, msg, subject, group, /* TODO: finish attachments */ null); } else { sendResponse = srvc.sendMessage(addrs, msg); } final String id = sendResponse.getId(); jresponse.put("success", true).put("text", "id: " + id); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:Executable.LinkImputeR.java
private static void writeSum(PrintWriter sum, Case c, VCF vcf, AccuracyStats stats, AccuracyStats cstats, AccuracyStats istats, boolean partial) { sum.print(c.getName()); sum.print("\t"); sum.print(vcf.getSamples().length);//from w w w .ja va2 s. c o m sum.print("\t"); sum.print(vcf.getPositions().length); sum.print("\t"); sum.print(dforms.format(stats.accuracy())); sum.print("\t"); sum.print(dforms.format(stats.correlation())); sum.print("\t"); sum.print(c.getFilterSummary()); sum.print("\t"); sum.print(c.getAdditional()); if (partial) { sum.print("\t["); sum.print(dforms.format(cstats.accuracy())); sum.print("/"); sum.print(dforms.format(istats.accuracy())); sum.print("]"); sum.print("\t["); sum.print(dforms.format(cstats.correlation())); sum.print("/"); sum.print(dforms.format(istats.correlation())); sum.print("]"); } sum.println(); sum.flush(); }