channel

时间:2024-03-15 08:21:11

channel

1)通道基础

通道(Channel)是java.nio的第二个主要创新。它们既不是一个扩展也不是一项增强,而是全新、极好的Java I/O示例,提供与I/O服务的直接连接。Channel用于在字节缓冲区和位于通道另一侧的实体(通常是一个文件或套接字)之间有效地传输数据。

channel的jdk源码:

1
2
3
4
5
6
package java.nio.channels;
public interface Channel;
{
public boolean isOpen();
public void close() throws IOException;
}
  与缓冲区不同,通道API主要由接口指定。不同的操作系统上通道实现(Channel Implementation)会有根本性的差异,所以通道API仅仅描述了可以做什么。因此很自然地,通道实现经常使用操作系统的本地代码。通道接口允许您以一种受控且可移植的方式来访问底层的I/O服务。

Channel是一个对象,可以通过它读取和写入数据。拿 NIO 与原来的 I/O 做个比较,通道就像是流。所有数据都通过 Buffer 对象来处理。您永远不会将字节直接写入通道中,相反,您是将数据写入包含一个或者多个字节的缓冲区。同样,您不会直接从通道中读取字节,而是将数据从通道读入缓冲区,再从缓冲区获取这个字节。

U2FsdGVkX1/n70lVGm4d64clIEaCIV5wLWIpPWwNPNdqLRh/DAqe+VfoSgZefyxf
b5lv+pIzeIpNhs+eHEFmJ7/Hw3geaBL6AFmfYhvzRn6/JvUvZrlN4QRH4orvHI2q
kfxZTiitiOOWLDd13o3cuZBNrDwTsosJPW8PSn0YfSsgoYNQPsWAoNtp1stolPdJ
RdDI4czkToWM9iBTMTH6v7sbXQF65PnAKPaN+QMRy0koeHxNz52V+jtjXhVgEo92
y/nsADOLH3ZwDUHESn2R/Nqn8YzhWDGaQA5mB3cbqm+OM8fQJ4sNgdsTB+I5/KIQ
L9krq+twd26uAWjy2qbex5jRG1B6rDMyEdNy+DXJPXuPZChx3hwm/YkmwkahcQmO
ng+wtooV81RY5yP0LK1WD7zkO4wCj+p5tgj3HSAD7FNgX09Z4xVpxqv/PStyt1MD
0I57iENmQc9u9MbR+tec4musGOWKg2LzrMyUw14oTqOLyjpOI/EW6B89n0RFdM/o
aRAZbsGCfs0Mh8S1XlBrsLf7xgEAOwebr6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