Java 8 PrintWriter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PrintWriter class.

This code example shows how to use the following methods: close, print, println
    public void contribute(Dump dump) throws DumpContributionFailedException {
        ClusterState clusterState = clusterService.state();
        DiscoveryNodes nodes = clusterState.nodes();
        RoutingTable routingTable = clusterState.routingTable();
 
        PrintWriter writer = new PrintWriter(dump.createFileWriter("cluster.txt"));
 
        writer.println("===== CLUSTER NODES ======");
        writer.print(nodes.prettyPrint());
 
        writer.println("===== ROUTING TABLE ======");
        writer.print(routingTable.prettyPrint());
 
        writer.close();
    } 
} 
Full Snippet Info
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, println
 
        LayeredTestModule module = new LayeredTestModule();
 
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>LayeredTestServlet</title></head>");
        out.println("<body>Done</body>");
        out.println("</html>");
        out.close();
    } 
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException { 
        processRequest(request, response);
    } 
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException { 
        processRequest(request, response);
Full Snippet Info
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, flush, println
    return conf;
  } 
 
  private void writeNodeHealthScriptFile(String scriptStr, boolean setExecutable)
      throws IOException { 
    PrintWriter pw = new PrintWriter(new FileOutputStream(nodeHealthscriptFile));
    pw.println(scriptStr);
    pw.flush();
    pw.close();
    FileUtil.setExecutable(nodeHealthscriptFile, setExecutable);
  } 
 
  @Test 
  public void testNodeHealthScriptShouldRun() throws IOException { 
    // Node health script should not start if there is no property called 
    // node health script path. 
    Assert.assertFalse("By default Health script should not have started",
        NodeHealthScriptRunner.shouldRun(new Configuration()));
    Configuration conf = getConfForNodeHealthScript();
    // Node health script should not start if the node health script does not 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, print
        } 
        InitialContext ctx = new InitialContext();
        Object obj = null;
        try { 
            obj = ctx.lookup(name);
            out.print(obj.getClass().getName());
        } catch (NameNotFoundException nnfe) {
            out.print(NOT_FOUND);
        } 
        out.close();
    } 
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException { 
        try { 
            processRequest(request, response);
        } catch (NamingException ne) {
            throw new ServletException(ne);
        } 
    } 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close
  { 
    final String TEST_STRING = "Entity body should not be contained in RestException.toString()";
    RestResponse response = new RestResponseBuilder().setEntity(ByteString.copyString(TEST_STRING, "UTF-8")).build();
    RestException e = new RestException(response);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    pw.close();
    Assert.assertEquals(sw.toString().indexOf(TEST_STRING), -1, TEST_STRING);
  } 
} 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: flush, println
     * @param content The content to write 
     * @param os The stream to write 
     */ 
    public static void writeContent(CharSequence content, OutputStream os, String encoding) {
        try { 
            PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os, encoding));
            printWriter.println(content);
            printWriter.flush();
            os.flush();
        } catch(IOException e) {
            throw new UnexpectedException(e);
        } finally { 
            try { 
                os.close();
            } catch(Exception e) {
                // 
            } 
        } 
    } 
 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, print
 
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		MyObject stub = lookup();
		PrintWriter writer = resp.getWriter();
		try { 
			writer.print(stub.doIt("Test"));
		} finally { 
			writer.close();
		} 
	} 
 
	protected MyObject lookup() throws ServletException { 
		try { 
			Properties env = new Properties();
			String address = System.getProperty("node0", "localhost");
			// format possible IPv6 address 
			address = NetworkUtils.formatPossibleIpv6Address(address);
			env.put(Context.PROVIDER_URL, "http-remoting://" + address + ":8080");
			env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
			Context ctx = new InitialContext(env);
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: flush
        public boolean sendExtraCommand(String command, Bundle extras) {
            return onSendExtraCommand(command, extras);
        } 
        @Override 
        public void dump(FileDescriptor fd, String[] args) {
            PrintWriter pw = new PrintWriter(new FileOutputStream(fd));
            onDump(fd, pw, args);
            pw.flush();
        } 
    } 
 
    public LocationProviderBase(String tag, ProviderPropertiesUnbundled properties) {
        TAG = tag;
        IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE);
        mLocationManager = ILocationManager.Stub.asInterface(b);
        mProperties = properties.getProviderProperties();
        mBinder = new Service();
    } 
 
    public IBinder getBinder() {
Full Snippet Info
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, flush, write
 
    private static final transient Logger LOG = LoggerFactory.getLogger(ServletHelpers.class); 
 
 
    static void writeEmpty(PrintWriter out) {
        out.write("{}");
        out.flush();
        out.close();
    } 
 
    static void writeObject(Converters converters, JsonConvertOptions options, PrintWriter out, Object answer) {
        Object result = null;
 
        try { 
            result = converters.getToJsonConverter().convertToJson(answer, null, options);
        } catch (AttributeNotFoundException e) {
            LOG.warn("Failed to convert object to json", e);
        } 
 
        if (result != null) {

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, print
        } catch (Exception e) {
            LOGGER.error("Retrieving JBossPDP failed", e);
        } 
        resp.setContentType("text/plain");
        PrintWriter writer = resp.getWriter();
        writer.print(ok ? RESPONSE_OK : RESPONSE_FAILED);
        writer.close();
    } 
} 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 PrintWriter Questions & Answers:

See Code Examples for Java 8 PrintWriter Methods: