當前位置: 首頁>>代碼示例>>Java>>正文


Java Socket.shutdownOutput方法代碼示例

本文整理匯總了Java中java.net.Socket.shutdownOutput方法的典型用法代碼示例。如果您正苦於以下問題:Java Socket.shutdownOutput方法的具體用法?Java Socket.shutdownOutput怎麽用?Java Socket.shutdownOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.shutdownOutput方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeResponse

import java.net.Socket; //導入方法依賴的package包/類
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();
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:22,代碼來源:MockWebServer.java

示例2: writeResponse

import java.net.Socket; //導入方法依賴的package包/類
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();
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:22,代碼來源:MockWebServer.java

示例3: writeResponse

import java.net.Socket; //導入方法依賴的package包/類
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();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:22,代碼來源:MockWebServer.java

示例4: writeResponse

import java.net.Socket; //導入方法依賴的package包/類
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();
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:17,代碼來源:MockWebServer.java

示例5: closeSocketOutput

import java.net.Socket; //導入方法依賴的package包/類
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());
    }
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:10,代碼來源:HttpProxyCacheServer.java

示例6: runServer

import java.net.Socket; //導入方法依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:isstac,項目名稱:kelinci,代碼行數:44,代碼來源:Kelinci.java

示例7: shutdownOutput

import java.net.Socket; //導入方法依賴的package包/類
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);
        }
    }
}
 
開發者ID:spacetimeme,項目名稱:DreamSocket,代碼行數:11,代碼來源:DreamTCPSocket.java


注:本文中的java.net.Socket.shutdownOutput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。