当前位置: 首页>>代码示例>>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;未经允许,请勿转载。