List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:jp.ikedam.jenkins.plugins.jobcopy_builder.ReplaceRegExpOperation.java
/** * Returns modified XML Document of the job configuration. * * Replace the strings in the job configuration: only applied to strings in text nodes, so the XML structure is never destroyed. * * @param doc/*from w w w. j a v a 2 s . c o m*/ * XML Document of the job to be copied (job/NAME/config.xml) * @param env * Variables defined in the build. * @param logger * The output stream to log. * @return modified XML Document. Return null if an error occurs. * @see jp.ikedam.jenkins.plugins.jobcopy_builder.AbstractXmlJobcopyOperation#perform(org.w3c.dom.Document, hudson.EnvVars, java.io.PrintStream) */ @Override public Document perform(final Document doc, final EnvVars env, final PrintStream logger) { final String fromStr = getFromStr(); String toStr = getToStr(); if (StringUtils.isEmpty(fromStr)) { logger.println("From String is empty"); return null; } if (toStr == null) { toStr = ""; } final String expandedFromStr = isExpandFromStr() ? env.expand(fromStr) : maskSpecialChars(fromStr); Pattern pattern; try { pattern = Pattern.compile(expandedFromStr); } catch (final PatternSyntaxException e) { logger.println("Error on regular expression: " + e.getMessage()); return null; } String expandedToStr = isExpandToStr() ? env.expand(toStr) : maskSpecialChars(toStr); if (StringUtils.isEmpty(expandedFromStr)) { logger.println("From String got to be empty"); return null; } if (expandedToStr == null) { expandedToStr = ""; } logger.print("Replacing with RegExp: " + expandedFromStr + " -> " + expandedToStr); try { // Retrieve all text nodes. final NodeList textNodeList = getNodeList(doc, "//text()"); // Perform replacing to all text nodes. // NodeList does not implement Collection, and foreach is not usable. for (int i = 0; i < textNodeList.getLength(); ++i) { final Node node = textNodeList.item(i); final String nodeValue = node.getNodeValue(); String newNodeValue = nodeValue; final Matcher matcher = pattern.matcher(nodeValue); // check all occurance while (matcher.find()) { newNodeValue = matcher.replaceAll(expandedToStr); } node.setNodeValue(newNodeValue); } logger.println(""); return doc; } catch (final Exception e) { logger.print("Error occured in XML operation"); e.printStackTrace(logger); return null; } }
From source file:com.hpe.application.automation.tools.run.SseBuilder.java
private Result createRunResults(FilePath filePath, Testsuites testsuites, PrintStream logger) { Result ret = Result.SUCCESS; try {// ww w. j a v a2 s .c o m if (testsuites != null) { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(Testsuites.class); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(testsuites, writer); filePath.write(writer.toString(), null); if (containsErrors(testsuites.getTestsuite())) { ret = Result.UNSTABLE; } } else { logger.println("Empty Results"); ret = Result.UNSTABLE; } } catch (Exception cause) { logger.print(String.format("Failed to create run results, Exception: %s", cause.getMessage())); ret = Result.UNSTABLE; } return ret; }
From source file:com.github.lindenb.jvarkit.tools.misc.AddLinearIndexToBed.java
protected int doWork(InputStream is, PrintStream out) throws IOException { final Pattern tab = Pattern.compile("[\t]"); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String line = null;//from ww w . ja v a 2s . c o m while ((line = in.readLine()) != null) { if (line.isEmpty() || line.startsWith("#") || line.startsWith("track") || line.startsWith("browser")) continue; String tokens[] = tab.split(line, 3); if (tokens.length < 2) { LOG.warn("Bad chrom/pos line:" + line); continue; } SAMSequenceRecord ssr = this.dictionary.getSequence(tokens[0]); if (ssr == null) { for (SAMSequenceRecord sr2 : this.dictionary.getSequences()) { LOG.info("available " + sr2.getSequenceName()); } throw new IOException("undefined chromosome:" + tokens[0]); } int pos0 = Integer.parseInt(tokens[1]); if (pos0 < 0 || pos0 >= ssr.getSequenceLength()) { LOG.warn("position is out of range for : " + line + " length(" + tokens[0] + ")=" + ssr.getSequenceLength()); } out.print(this.tid2offset[ssr.getSequenceIndex()] + pos0); out.print('\t'); out.print(line); out.println(); if (out.checkError()) break; } return 0; }
From source file:net.lr.jmsbridge.BridgeServlet.java
/** * Forward HTTP request to a jms queue and listen on a temporary queue for the reply. * Connects to the jms server by using the username and password from the HTTP basic auth. *///from w w w . j av a2 s .c o m @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String authHeader = req.getHeader("Authorization"); if (authHeader == null) { resp.setHeader("WWW-Authenticate", "Basic realm=\"Bridge\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "auth"); return; } UserNameAndPassword auth = extractUserNamePassword(authHeader); PrintStream out = new PrintStream(resp.getOutputStream()); String contextPath = req.getContextPath(); String uri = req.getRequestURI(); String queueName = uri.substring(contextPath.length() + 1); final StringBuffer reqContent = retrieveRequestContent(req.getReader()); ConnectionFactory cf = connectionPool.getConnectionFactory(auth); JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(cf); jmsTemplate.setReceiveTimeout(10000); final Destination replyDest = connectionPool.getReplyDestination(cf, auth); jmsTemplate.send(queueName, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(reqContent.toString()); message.setJMSReplyTo(replyDest); return message; } }); Message replyMsg = jmsTemplate.receive(replyDest); if (replyMsg instanceof TextMessage) { TextMessage replyTMessage = (TextMessage) replyMsg; try { out.print(replyTMessage.getText()); } catch (JMSException e) { JmsUtils.convertJmsAccessException(e); } } }
From source file:edu.wisc.jmeter.MonitorListener.java
/** * Saves data from the last response to a file *//*from w w w.j a va2 s .c om*/ private void saveResponseToFile(SampleResult sampleResult, Date now, String userId, String hostName, String errorMessages, int errorCount, int messageCount) { final String formatedDate; synchronized (RESPONSE_FILE_DATE_FORMAT) { formatedDate = RESPONSE_FILE_DATE_FORMAT.format(now); } final File responseFile = new File(logLocation, formatedDate + "." + hostName + ".response"); PrintStream ps = null; try { ps = new PrintStream(responseFile); final String respHeaders = sampleResult.getResponseHeaders(); final String respData = sampleResult.getResponseDataAsString(); ps.println("Sampler Label: " + sampleResult.getSampleLabel()); ps.println("Portal User: " + userId); ps.println("Consecutive Error Count: " + errorCount); ps.println("Sent Message Count: " + messageCount); ps.println("Error Messages: " + errorMessages); ps.println("--------------------------------------------------------------------------------"); ps.print(respHeaders); ps.println("--------------------------------------------------------------------------------"); ps.print(respData); ps.flush(); log("Saved response to: " + responseFile); } catch (FileNotFoundException fnfe) { log("Failed to save response headers and body to file", fnfe); } finally { IOUtils.closeQuietly(ps); } }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
public String outputAST(String treeString, PrintStream out, boolean jsonOutput, int indent) throws JSONException { if (out != null) { out.print(indentString(indent)); out.println("ABSTRACT SYNTAX TREE:"); out.print(indentString(indent + 2)); out.println(treeString);//from w w w.j a v a 2 s. c o m } return jsonOutput ? treeString : null; }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
private Object toJson(String header, String message, PrintStream out, ExplainWork work) throws Exception { if (work.isFormatted()) { return message; }/*from w ww .j a v a 2s.c o m*/ out.print(header); out.println(": "); out.print(indentString(2)); out.println(message); return null; }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
private Object toJson(String header, List<String> messages, PrintStream out, ExplainWork work) throws Exception { if (work.isFormatted()) { return new JSONArray(messages); }/* w w w. j a v a 2 s. com*/ out.print(header); out.println(": "); for (String message : messages) { out.print(indentString(2)); out.print(message); out.println(); } return null; }
From source file:org.archive.crawler.Heritrix.java
/** * Perform preparation to use an ad-hoc, created-as-necessary * certificate/keystore for HTTPS access. A keystore with new * cert is created if necessary, as adhoc.keystore in the working * directory. Otherwise, a preexisting adhoc.keystore is read * and the certificate fingerprint shown to assist in operator * browser-side verification./*from ww w. j a v a 2s.c o m*/ * @param startupOut where to report fingerprint */ protected void useAdhocKeystore(PrintStream startupOut) { try { File keystoreFile = new File(ADHOC_KEYSTORE); if (!keystoreFile.exists()) { String[] args = { "-keystore", ADHOC_KEYSTORE, "-storepass", ADHOC_PASSWORD, "-keypass", ADHOC_PASSWORD, "-alias", "adhoc", "-genkey", "-keyalg", "RSA", "-dname", "CN=Heritrix Ad-Hoc HTTPS Certificate", "-validity", "3650" }; // 10 yr validity KeyTool.main(args); } KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream inStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(keystoreFile)); keystore.load(inStream, ADHOC_PASSWORD.toCharArray()); Certificate cert = keystore.getCertificate("adhoc"); byte[] certBytes = cert.getEncoded(); byte[] sha1 = MessageDigest.getInstance("SHA1").digest(certBytes); startupOut.print("Using ad-hoc HTTPS certificate with fingerprint...\nSHA1"); for (byte b : sha1) { startupOut.print(String.format(":%02X", b)); } startupOut.println("\nVerify in browser before accepting exception."); } catch (Exception e) { // fatal, rethrow throw new RuntimeException(e); } }
From source file:org.apache.hadoop.hive.ql.exec.ExplainTask.java
private JSONObject outputPlan(Task<?> task, PrintStream out, JSONObject parentJSON, boolean extended, boolean jsonOutput, int indent) throws Exception { if (out != null) { out.print(indentString(indent)); out.print("Stage: "); out.print(task.getId());/*from www . j a v a 2s . c o m*/ out.print("\n"); } // Start by getting the work part of the task and call the output plan for // the work JSONObject jsonOutputPlan = outputPlan(task.getWork(), out, extended, jsonOutput, jsonOutput ? 0 : indent + 2); if (out != null) { out.println(); } if (jsonOutput) { parentJSON.put(task.getId(), jsonOutputPlan); } return null; }