List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:mx.unam.ecologia.gye.coalescence.app.EvaluateAncestry.java
protected static final void process(CompoundSequence mrca, List leaves) { try {/*ww w. j a va 2s. com*/ PrintWriter pw = new PrintWriter(System.out); HaplotypeFreqSet len1 = new HaplotypeFreqSet(new CompoundSequenceLengthComparator()); HaplotypeFreqSet len2 = new HaplotypeFreqSet(new CompoundSequenceLengthComparator()); HaplotypeFreqSet ident = new HaplotypeFreqSet(new CompoundSequenceIdentityComparator()); for (int i = 0; i < leaves.size(); i++) { UniParentalGene upgene = (UniParentalGene) leaves.get(i); CompoundSequence h = upgene.getCompoundSequence(); len1.add(h); ident.add(h); CompoundSequence cs = h.getCopy(); cs.setLocus(true); len2.add(cs); } //Identity pw.println("IDENTITY"); ident.sort(new CSAncestryComparator()); CompoundSequence cs = ident.get(0); pw.println("MA: " + ident.contains(cs)); pw.println("MF: " + (ident.findMostFrequent() + 1)); pw.println(ident.toFullString()); pw.println(); pw.println(); pw.println("MULTILOCUS"); pw.println("MA: " + len1.contains(cs)); pw.println("MF: " + (len1.findMostFrequent() + 1)); pw.println(len1.toResumeString()); pw.println(); pw.println(); pw.println("LOCUS"); cs.setLocus(true); pw.println("MA: " + len2.contains(cs)); pw.println("MF: " + (len2.findMostFrequent() + 1)); pw.println(len2.toResumeString()); pw.flush(); SparseGraph sg = new SparseGraph(); List<CompoundSequence> ht = len1.getHaplotypes(); //add vertices List<SparseVertex> vertices = new ArrayList<SparseVertex>(ht.size()); for (Iterator<CompoundSequence> iter = ht.iterator(); iter.hasNext();) { CompoundSequence cseq = iter.next(); SparseVertex sv = new SparseVertex(); sv.addUserDatum("seq", cseq, UserData.SHARED); sv.addUserDatum("freq", len1.getFrequency(cseq), UserData.SHARED); if (cseq.equals(cs)) { sv.addUserDatum("mf", true, UserData.SHARED); } sg.addVertex(sv); vertices.add(sv); } //add edges for (int i = 0; i < ht.size(); i++) { for (int j = 0; j <= i; j++) { double d = DistanceCalculator.calculateMultilocusLengthDistance(ht.get(i), ht.get(j)); UndirectedSparseEdge ue = new UndirectedSparseEdge(vertices.get(i), vertices.get(j)); ue.setUserDatum(EDGE_WEIGHT_KEY, new Double(d), UserData.SHARED); if (d != 0) { sg.addEdge(ue); } } } //System.out.println(sg.toString()); //System.out.println(GraphMatrixOperations.graphToSparseMatrix(sg,EDGE_WEIGHT_KEY)); visualizeGraph(sg); //Prim SparseGraph nsg = new SparseGraph(); FibonacciHeap<Vertex, Double> q = new FibonacciHeap<Vertex, Double>(); Map<Vertex, Vertex> pi = new HashMap<Vertex, Vertex>((int) (ht.size() * 1.3)); //System.out.println("Have structures"); Vertex r = null; for (SparseVertex u : vertices) { q.add(u, Double.MAX_VALUE); u.copy(nsg); if (r == null) { r = u; } else { //start from max freq r = (((Integer) r.getUserDatum("freq")).compareTo((Integer) u.getUserDatum("freq")) > 0) ? r : u; } } q.decreaseKey(r, 0d); //System.out.println("initialized starting loop"); do { Vertex u = (Vertex) q.popMin(); Set<Vertex> s = u.getNeighbors(); for (Vertex v : s) { Edge e = u.findEdge(v); double w = (Double) e.getUserDatum(EDGE_WEIGHT_KEY); if (q.contains(v) && w < q.getPriority(v)) { pi.put(v, u); q.decreaseKey(v, w); } } } while (q.size() > 0); //put edges for (Map.Entry<Vertex, Vertex> entry : pi.entrySet()) { Vertex v = entry.getKey(); Vertex u = entry.getValue(); u.findEdge(v).copy(nsg); } /* for(SparseVertex sv:vertices) { //edges Set s = sv.getIncidentEdges(); Edge[] edges = (Edge[])s.toArray(new Edge[s.size()]); //sort Arrays.sort(edges,new Comparator<Edge>() { public int compare(Edge o1, Edge o2) { return ((Double)o2.getUserDatum(EDGE_WEIGHT_KEY)).compareTo((Double)o1.getUserDatum(EDGE_WEIGHT_KEY)); } }); System.out.println(Arrays.toString(edges)); //just leave the edge with the lowest weight for(Edge e:edges) { if(sv.degree() > 1 && e.getOpposite(sv).degree() > 1) { sg.removeEdge(e); System.out.println("Removing " + e.toString() + "::w="+e.getUserDatum(EDGE_WEIGHT_KEY)); } } System.out.println(sv.toString()); } */ visualizeGraph(nsg); } catch (Exception ex) { log.error("process()", ex); } }
From source file:SessionTimer.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); session.setMaxInactiveInterval(2 * 60 * 60); // two hours out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }
From source file:nl.npcf.eav.web.EAVExceptionResolver.java
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {// w w w.ja v a 2 s . c o m String pathInfo = request.getPathInfo(); if (pathInfo != null && pathInfo.startsWith("/edit")) { try { PrintWriter out = response.getWriter(); out.println("<html><head><title>Exception</title></head><body>"); out.println("<pre>"); out.println(EAVResponse.getStackTrace(e)); out.println("</pre>"); out.println("</body>"); } catch (IOException e1) { logger.fatal("Can't report exception"); } } else { response.setContentType("text/xml"); try { new EAVXStream().toXML(EAVResponse.create(e), response.getOutputStream()); } catch (IOException e1) { logger.fatal("Cannot respond with exception", e); } } return null; }
From source file:ErrorGen.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //check the servlet exception Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name"); if (servletName == null) servletName = "Unknown"; String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null) requestUri = "Unknown"; response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Error page</title>"); out.println("</head>"); out.println("<body>"); if (throwable == null) { out.println("<h2>The error information is not available</h2>"); out.println("Please return to the <a href=\"" + response.encodeURL("http://www.java2s.com") + "\">home page</a>"); } else {//from www . j a v a 2s . co m out.println("<h2>Here is the error information</h2>"); out.println("The servlet name associated with throwing the exception: " + servletName + "<br><br>"); out.println("The type of exception: " + throwable.getClass().getName() + "<br><br>"); out.println("The request URI: " + requestUri + "<br><br>"); out.println("The exception message: " + throwable.getMessage()); } out.println("</body>"); out.println("</html>"); out.close(); }
From source file:marytts.tools.dbselection.DatabaseSelector.java
/** * Print the list of selected files// w w w. j a v a 2 s . co m * * @param filename the file to print to * @param selected the list of files */ private static void storeResult(String filename, Set<Integer> selected) { PrintWriter out; try { out = new PrintWriter(new FileWriter(new File(filename))); } catch (Exception e) { e.printStackTrace(); throw new Error("Error storing result"); } for (int sel : selected) { out.println(sel); } out.flush(); out.close(); }
From source file:ru.mystamps.web.controller.RobotsTxtController.java
@GetMapping(Url.ROBOTS_TXT) @SuppressWarnings("PMD.AvoidDuplicateLiterals") public void getRobotsText(HttpServletResponse response) { response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); try {//from w ww .j a va 2s .c o m PrintWriter writer = response.getWriter(); writer.println("# robots.txt for " + Url.PUBLIC_URL); writer.println("User-Agent: *"); writer.println("Disallow: " + Url.REGISTRATION_PAGE); writer.println("Disallow: " + Url.ACTIVATE_ACCOUNT_PAGE); writer.println("Disallow: " + Url.AUTHENTICATION_PAGE); writer.println("Disallow: " + Url.LOGIN_PAGE); writer.println("Disallow: " + Url.ADD_COUNTRY_PAGE); writer.println("Disallow: " + Url.ADD_SERIES_PAGE); writer.println("Disallow: " + Url.ADD_CATEGORY_PAGE); writer.println("Disallow: " + Url.FORBIDDEN_PAGE); writer.println("Disallow: " + Url.NOT_FOUND_PAGE); writer.println("Disallow: " + Url.INTERNAL_ERROR_PAGE); writer.println("Sitemap: " + Url.PUBLIC_URL + Url.SITEMAP_XML); } catch (IOException ex) { LOG.error("Can't return robots.txt: {}", ex.getMessage()); } }
From source file:CookieReader.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { Cookie cookie = null;//from w w w . java2 s . c o m //Get an array of Cookies associated with this domain Cookie[] cookies = request.getCookies(); boolean hasCookies = false; if (cookies != null) hasCookies = true; // display the name/value of each cookie response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Cookie information</title>"); out.println("</head>"); out.println("<body>"); if (hasCookies) { out.println("<h2> The name and value of each found cookie</h2>"); for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; out.println("Name of cookie #" + (i + 1) + ": " + cookie.getName() + "<br>"); out.println("Value of cookie #" + (i + 1) + ": " + cookie.getValue() + "<br><br>"); } } else { out.println("<h2> This request did not include any cookies</h2>"); } out.println("</body>"); out.println("</html>"); out.close(); }
From source file:com.excella.deploy.agent.core.StatusServlet.java
/** * {@inheritDoc}/*w ww. j a va2 s . co m*/ */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.info("Recieved status request command over http [" + request.getRequestURI() + "]"); try { log.debug("Reporting Status..."); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.println("<h1>Deploy Agent Status</h1>"); writer.println("<p>"); writer.println("Everything is Great!"); writer.println("</p>"); ((Request) request).setHandled(true); } catch (Exception e) { log.error("Failed to report Status.", e); } }
From source file:net.metanotion.sqlc.SQLC.java
private static void generateStructs(final String outputFolder, final StructManager sm, final Set<String> implicits, final Map<String, String> implicitDocs, final Map<String, Boolean> implicitVisibility, final Iterable<String> srcPathes) throws IOException { for (final Map.Entry<String, GetInitializer> e : sm) { if (!implicits.contains(e.getKey())) { continue; }// w w w . ja v a 2s . c om final String visibility = implicitVisibility.get(e.getKey()).booleanValue() ? "public " : " "; final String docString = implicitDocs.get(e.getKey()); final GetInitializer gi = e.getValue(); if (needToGenerateStruct(e.getKey(), gi, srcPathes)) { final Struct s = (Struct) gi; final String[] name = e.getKey().split("\\."); final String[] pkg = new String[name.length - 1]; for (int i = 0; i < pkg.length; i++) { pkg[i] = name[i]; } final FileOutputStream fos = new FileOutputStream(mkPath(outputFolder, pkg, name[pkg.length])); final PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF-8")); if (pkg.length > 0) { writer.print("package "); String sep = ""; for (String pe : pkg) { writer.print(sep + pe); sep = "."; } writer.println(";"); writer.println(""); } System.out.println("GENERATING: " + visibility + " " + name[pkg.length]); writer.print("/** "); if (docString != null) { writer.println(docString.substring(3, docString.length() - 2)); } writer.println("<i>This is a data/struct/value class generated by the SQLC compiler.</i> */"); writer.println("@javax.annotation.Generated(\"net.metanotion.sqlc.SQLC\") " + visibility + "final class " + name[pkg.length] + " {"); for (final String p : s.listProperties()) { writer.print("\tpublic "); writer.print(s.getType(p)); writer.println(" " + p + ";"); } writer.println("}"); writer.close(); fos.close(); } } }
From source file:RequestDisplay.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { ContextObject obj = (ContextObject) request.getAttribute("com.java2s.RequestObject"); //display the attribute's Map keys response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Request Attribute</title></head><body>"); out.println("<h2>Request attribute values</h2>"); if (obj != null) out.println(obj.getValues());// w w w . j av a 2s .c o m out.println("</body></html>"); }