Java Code Examples for java.net.Socket.shutdownOutput()

The following are Jave code examples for showing how to use shutdownOutput() of the java.net.Socket class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: springboot-shiro-cas-mybatis   File: MockWebServer.java   Source Code and License Vote up 6 votes
private void writeResponse(final Socket socket) throws IOException {
    logger.debug("Socket response for resource {}", resource.getFilename());
    final OutputStream out = socket.getOutputStream();
    out.write(STATUS_LINE.getBytes());
    out.write(header("Content-Length", this.resource.contentLength()));
    out.write(header("Content-Type", this.contentType));
    out.write(SEPARATOR.getBytes());

    final byte[] buffer = new byte[BUFFER_SIZE];
    try (InputStream in = this.resource.getInputStream()) {
        int count = 0;
        while ((count = in.read(buffer)) > -1) {
            out.write(buffer, 0, count);
        }
    }
    logger.debug("Wrote response for resource {} for {}",
            resource.getFilename(),
            resource.contentLength());

    socket.shutdownOutput();
}
 
Example 2
Project: springboot-shiro-cas-mybatis   File: MockWebServer.java   Source Code and License Vote up 6 votes
private void writeResponse(final Socket socket) throws IOException {
    logger.debug("Socket response for resource {}", resource.getFilename());
    final OutputStream out = socket.getOutputStream();
    out.write(STATUS_LINE.getBytes());
    out.write(header("Content-Length", this.resource.contentLength()));
    out.write(header("Content-Type", this.contentType));
    out.write(SEPARATOR.getBytes());

    final byte[] buffer = new byte[BUFFER_SIZE];
    try (final InputStream in = this.resource.getInputStream()) {
        int count = 0;
        while ((count = in.read(buffer)) > -1) {
            out.write(buffer, 0, count);
        }
    }
    logger.debug("Wrote response for resource {} for {}",
            resource.getFilename(),
            resource.contentLength());

    socket.shutdownOutput();
}
 
Example 3
Project: cas-5.1.0   File: MockWebServer.java   Source Code and License Vote up 6 votes
private void writeResponse(final Socket socket) throws IOException {
    LOGGER.debug("Socket response for resource [{}]", resource.getFilename());
    final OutputStream out = socket.getOutputStream();
    out.write(STATUS_LINE.getBytes());
    out.write(header("Content-Length", this.resource.contentLength()));
    out.write(header("Content-Type", this.contentType));
    out.write(SEPARATOR.getBytes());

    final byte[] buffer = new byte[BUFFER_SIZE];
    try(InputStream in = this.resource.getInputStream()) {
        int count = 0;
        while ((count = in.read(buffer)) > -1) {
            out.write(buffer, 0, count);
        }
    }
    LOGGER.debug("Wrote response for resource [{}] for [{}]",
            resource.getFilename(),
            resource.contentLength());

    socket.shutdownOutput();
}
 
Example 4
Project: cas4.0.x-server-wechat   File: MockWebServer.java   Source Code and License Vote up 6 votes
private void writeResponse(final Socket socket) throws IOException {
    final OutputStream out = socket.getOutputStream();
    out.write(STATUS_LINE.getBytes());
    out.write(header("Content-Length", this.resource.contentLength()));
    out.write(header("Content-Type", this.contentType));
    out.write(SEPARATOR.getBytes());

    final byte[] buffer = new byte[BUFFER_SIZE];
    final InputStream in = this.resource.getInputStream();
    int count = 0;
    while ((count = in.read(buffer)) > -1) {
        out.write(buffer, 0, count);
    }
    in.close();
    socket.shutdownOutput();
}
 
Example 5
Project: cas-server-4.2.1   File: MockWebServer.java   Source Code and License Vote up 6 votes
private void writeResponse(final Socket socket) throws IOException {
    logger.debug("Socket response for resource {}", resource.getFilename());
    final OutputStream out = socket.getOutputStream();
    out.write(STATUS_LINE.getBytes());
    out.write(header("Content-Length", this.resource.contentLength()));
    out.write(header("Content-Type", this.contentType));
    out.write(SEPARATOR.getBytes());

    final byte[] buffer = new byte[BUFFER_SIZE];
    try (final InputStream in = this.resource.getInputStream()) {
        int count = 0;
        while ((count = in.read(buffer)) > -1) {
            out.write(buffer, 0, count);
        }
    }
    logger.debug("Wrote response for resource {} for {}",
            resource.getFilename(),
            resource.contentLength());

    socket.shutdownOutput();
}
 
Example 6
Project: AndroidVideoCache   File: HttpProxyCacheServer.java   Source Code and License Vote up 5 votes
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        LOG.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 7
Project: kelinci   File: Kelinci.java   Source Code and License Vote up 5 votes
/**
 * Method to run in a thread to accept requests coming
 * in over TCP and put them in a queue.
 */
private static void runServer() {

	try (ServerSocket ss = new ServerSocket(port)) {
		if (verbosity > 1)
			System.out.println("Server listening on port " + port);

		while (true) {
			Socket s = ss.accept();
			if (verbosity > 1)
				System.out.println("Connection established.");

			boolean status = false;
			if (requestQueue.size() < maxQueue) {
				status = requestQueue.offer(new FuzzRequest(s));
				if (verbosity > 1)
					System.out.println("Request added to queue: " + status);
			} 
			if (!status) {
				if (verbosity > 1)
					System.out.println("Queue full.");
				OutputStream os = s.getOutputStream();
				os.write(STATUS_QUEUE_FULL);
				os.flush();
				s.shutdownOutput();
				s.shutdownInput();
				s.close();
				if (verbosity > 1)
					System.out.println("Connection closed.");
			}
		}
	} catch (BindException be) {
		System.err.println("Unable to bind to port " + port);
		System.exit(1);
	} catch (Exception e) {
		System.err.println("Exception in request server");
		e.printStackTrace();
		System.exit(1);
	}
}
 
Example 8
Project: DreamSocket   File: DreamTCPSocket.java   Source Code and License Vote up 5 votes
private static void shutdownOutput(Socket socket) {
    if (socket != null && !socket.isOutputShutdown()) {
        try {
            LoggerFactory.getLogger().info("关闭Socket输出...");
            socket.shutdownOutput();
        } catch (IOException e) {
            LoggerFactory.getLogger().error("关闭Socket输出异常", e);
        }
    }
}