Example usage for java.net Socket getInputStream

List of usage examples for java.net Socket getInputStream

Introduction

In this page you can find the example usage for java.net Socket getInputStream.

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Returns an input stream for this socket.

Usage

From source file:jetbrains.exodus.util.Streamer.java

public Streamer(@NotNull Socket socket) throws IOException {
    socketInput = new BufferedReader(new InputStreamReader(socket.getInputStream()), BUFFER_SIZE);
    socketOutput = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
}

From source file:Whois.java

public String whois(String query, String server) throws IOException {
    Socket sock = new Socket(server, 43);
    int c = 0;//  w w w .  j  av  a2 s.  c om
    String outstring = "";
    OutputStream os = sock.getOutputStream();
    InputStream is = sock.getInputStream();
    query += "\r\n";
    os.write(query.getBytes("iso8859_1"));
    try {
        while (c != -1) {
            c = is.read();
            if (c != -1)
                outstring += (char) c;
        }
    } catch (IOException e) {
    }
    return outstring;
}

From source file:org.apache.axis2.transport.testkit.util.tcpmon.Relay.java

public Relay(Socket inSocket, Socket outSocket, boolean isResponse) throws IOException {
    this.inSocket = inSocket;
    this.in = inSocket.getInputStream();
    this.out = outSocket.getOutputStream();
    if (isResponse) {
        connectionSpec = outSocket.getRemoteSocketAddress() + " <- " + inSocket.getRemoteSocketAddress();
    } else {// www. j  a va2s . co  m
        connectionSpec = inSocket.getRemoteSocketAddress() + " -> " + outSocket.getRemoteSocketAddress();
    }
}

From source file:Main.java

public void run() {
    while (true) {
        try {// w  ww .  j av a 2s.c o m
            System.out.println("Waiting for client on port " + serverSocket.getLocalPort() + "...");
            Socket server = serverSocket.accept();

            System.out.println("Just connected to " + server.getRemoteSocketAddress());
            DataInputStream in = new DataInputStream(server.getInputStream());
            System.out.println(in.readUTF());

            DataOutputStream out = new DataOutputStream(server.getOutputStream());
            out.writeUTF("Thank you for connecting to " + server.getLocalSocketAddress() + "\nGoodbye!");

            server.close();
        } catch (SocketTimeoutException s) {
            System.out.println("Socket timed out!");
            break;
        } catch (IOException e) {
            e.printStackTrace();
            break;
        }
    }
}

From source file:delete.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w  w . j  a  va 2  s.  com
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    Socket s = new Socket("localhost", 9999);

    DataInputStream in = new DataInputStream(s.getInputStream());
    DataOutputStream outD = new DataOutputStream(s.getOutputStream());

    outD.writeUTF(request.getParameter("employee_id"));

    in.readUTF();

    s.close();

    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

        out.println("Deleted");
    }
}

From source file:de.ingrid.communication.authentication.BasicSchemeConnector.java

private DataInputStream createInput(Socket socket) throws IOException {
    InputStream inputStream = socket.getInputStream();
    DataInputStream dataInput = new DataInputStream(new BufferedInputStream(inputStream, 65535));
    return dataInput;
}

From source file:com.dc.tes.License.java

private static String LicenseServerConnect(Message request) {
    String license = "";
    Socket client = null;
    try {// w  w w  .  j  a v a  2 s  .co m
        client = new Socket(LICENSE_SERVER_IP, LICENSE_SERVER_PORT);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "Lisence?";
        log.error(license);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "Lisence?";
        log.error(license);
    }

    try {
        client.getOutputStream().write(request.Export());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "?Lisence??";
        log.error(license);
    }
    Message response = null;
    try {
        response = new Message(client.getInputStream());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        license = "?Lisence??";
        log.error(license);
    }
    if (response.getInteger(MessageItem.LICENSE.AVAILABLE) == 0) {
        license = "License???"
                + response.getString(MessageItem.LICENSE.MSG);
        log.error(license);
    }
    if (request.getInteger(MessageItem.LICENSE.SIGN) == 0) {
        license = response.getString(MessageItem.LICENSE.LICENSEFILE);
    }
    return license;
}

From source file:cn.sh.zyh.ftpserver.impl.representation.AsciiRepresentation.java

/**
 * Gets the input stream of special socket.
 * //from  www  .j av a2s .  c om
 * @param socket
 *            the socket
 * 
 * @return the input stream
 * 
 * @throws IOException
 *             the IO exception
 * @see cn.sh.zyh.ftpserver.impl.representation.Representation#getInputStream(java.net.Socket)
 */
public InputStream getInputStream(final Socket socket) throws IOException {
    return new FromNetASCIIInputStream(socket.getInputStream());
}

From source file:org.accada.hal.impl.sim.multi.SimulatorServerController.java

private void register(Socket socket) throws IOException {
    InputStream in = socket.getInputStream();

    // get arguments
    StringBuffer definition = new StringBuffer();
    int buf = in.read();
    do {//from w w  w .j av  a2 s . c  om
        definition.append((char) buf);
        buf = in.read();
    } while ((char) buf != SimulatorServerTokens.EOL);

    SimulatorClientStub readerSimulator = new SimulatorClientStub(socket.getOutputStream(),
            definition.toString());
    readerSimulators.put(readerSimulator.getReaderId(), readerSimulator);
}

From source file:net.javacrumbs.mocksocket.SampleTest.java

@Test
public void testResponse() throws Exception {
    byte[] mockData = new byte[] { 1, 2, 3, 4 };
    expectCall().andReturn(data(mockData));

    Socket socket = SocketFactory.getDefault().createSocket("example.org", 1234);
    byte[] data = IOUtils.toByteArray(socket.getInputStream());
    socket.close();// w w  w . j a  v a2 s.  co m
    assertThat(data, is(mockData));
}