Java Socket Write getWriter(Socket socket)

Here you can find the source of getWriter(Socket socket)

Description

Make a PrintWriter to send outgoing data.

License

Open Source License

Parameter

Parameter Description
socket a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static PrintWriter getWriter(Socket socket) throws IOException 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (C) Devamatre Inc. 2009 - 2018. All rights reserved.
 * //  w w  w  . j  a  v  a2  s  .c  o m
 * This code is licensed to Devamatre under one or more contributor license 
 * agreements. The reproduction, transmission or use of this code, in source 
 * and binary forms, with or without modification, are permitted provided 
 * that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * 
 * Devamatre reserves the right to modify the technical specifications and or 
 * features without any prior notice.
 *****************************************************************************/

import java.io.IOException;

import java.io.PrintWriter;

import java.net.Socket;

public class Main {
    /**
     * Make a PrintWriter to send outgoing data. This PrintWriter will
     * automatically flush stream when <code>println(...)</code> is called.
     * 
     * 
     * @param socket
     * @return
     * @throws IOException
     */
    public static PrintWriter getWriter(Socket socket) throws IOException {
        /* autoFlush set to be true */
        return (new PrintWriter(socket.getOutputStream(), true));
    }
}

Related

  1. copy(final Socket inputSocket, final Socket outputSocket)
  2. createObjectOutputStream(Socket socket)
  3. createWriter(Socket socket)
  4. getOutputStream(Socket socket)
  5. getOutputStreamFromSocket(final Socket socket)
  6. openWriter(Socket socket)
  7. writeData(Socket id, byte[] data, int len)
  8. writeDatasIntoSocket(Socket socket, String datas)
  9. writeFromServer(Socket sck, String row)