`
Donald_Draper
  • 浏览: 950802 次
社区版块
存档分类
最新评论

SeekableByteChannel接口定义

    博客分类:
  • NIO
nio 
阅读更多
ByteChannel,分散聚集通道接口的定义(SocketChannel):http://donald-draper.iteye.com/blog/2371065
package java.nio.channels;

import java.nio.ByteBuffer;
import java.io.IOException;

/**
 * A byte channel that maintains a current <i>position</i> and allows the
 * position to be changed.
 *SeekableByteChannel维护是一个当前position,运行修改position。
 * <p> A seekable byte channel is connected to an entity, typically a file,
 * that contains a variable-length sequence of bytes that can be read and
 * written. The current position can be {@link #position() <i>queried</i>} and
 * {@link #position(long) <i>modified</i>}. The channel also provides access to
 * the current <i>size</i> of the entity to which the channel is connected. The
 * size increases when bytes are written beyond its current size; the size
 * decreases when it is {@link #truncate <i>truncated</i>}.
 *SeekableByteChannel连接一个实体,典型为一个包含可变长度的字节序列文件,可以读取
 和写。可通过#position方法获取当前位置,通过#position(long)修改当前position。通道
 提供了访问通道连接实体的当前size。当字节序列被写到实体时,实体size增加;当压缩时,
 实体size减少。
 * <p> The {@link #position(long) position} and {@link #truncate truncate} methods
 * which do not otherwise have a value to return are specified to return the
 * channel upon which they are invoked. This allows method invocations to be
 * chained. Implementations of this interface should specialize the return type
 * so that method invocations on the implementation class can be chained.
 *#position(long)和#truncate方法,在调用时,返回的值是不确定。这些方法可以链式调用。
 接口的实现,将该使这些方法返回一个精确的子,以便链式调用。
 * @since 1.7
 * @see java.nio.file.Files#newByteChannel
 */

public interface SeekableByteChannel
    extends ByteChannel
{
    /**
     * Reads a sequence of bytes from this channel into the given buffer.
     *从通道读取字节序列,写到buffer中
     * <p> Bytes are read starting at this channel's current position, and
     * then the position is updated with the number of bytes actually read.
     * Otherwise this method behaves exactly as specified in the {@link
     * ReadableByteChannel} interface.
     从当前通道的postion位置开始读取字节,当实际字节被读取时,则更细positon。其他
     的和ReadableByteChannel接口相同
     */
    @Override
    int read(ByteBuffer dst) throws IOException;

    /**
     * Writes a sequence of bytes to this channel from the given buffer.
     *从给定的buffer,读取字节序列写到通道中
     * <p> Bytes are written starting at this channel's current position, unless
     * the channel is connected to an entity such as a file that is opened with
     * the {@link java.nio.file.StandardOpenOption#APPEND APPEND} option, in
     * which case the position is first advanced to the end. The entity to which
     * the channel is connected is grown, if necessary, to accommodate the
     * written bytes, and then the position is updated with the number of bytes
     * actually written. Otherwise this method behaves exactly as specified by
     * the {@link WritableByteChannel} interface.
     从通道当前的位置写字节序列,除非通道连接一个实体,比如以StandardOpenOption#APPEND
     配置选项打开的文件,在这种情况下,position首先定位到文件的尾部。通道连接的实际将会
     增加,如果需要,计算写的字节数,更新position。其他方法与WritableByteChannel相同。
     */
    @Override
    int write(ByteBuffer src) throws IOException;

    /**
     * Returns this channel's position.
     *返回当前通道的位置
     * @return  This channel's position,
     *          a non-negative integer counting the number of bytes
     *          from the beginning of the entity to the current position
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IOException
     *          If some other I/O error occurs
     */
    long position() throws IOException;

    /**
     * Sets this channel's position.
     *设置通道的位置
     * <p> Setting the position to a value that is greater than the current size
     * is legal but does not change the size of the entity.  A later attempt to
     * read bytes at such a position will immediately return an end-of-file
     * indication.  A later attempt to write bytes at such a position will cause
     * the entity to grow to accommodate the new bytes; the values of any bytes
     * between the previous end-of-file and the newly-written bytes are
     * unspecified.
     *如果设置position大于当前实体size,是合法的,不会改变实体的size。尝试从设置后的
     position位置读取字节,position将会立即定位到文件的末端。此时尝试写字节序列,
     将会引起实体的增加。
     * <p> Setting the channel's position is not recommended when connected to
     * an entity, typically a file, that is opened with the {@link
     * java.nio.file.StandardOpenOption#APPEND APPEND} option. When opened for
     * append, the position is first advanced to the end before writing.
     *当通道连接一个实体时,不建议设置通道的position,特别是一个以StandardOpenOption#APPEND
     配置选项打开的文件,在这种情况下,在写之前,首先定位position的位置到文件的末尾。
     * @param  newPosition
     *         The new position, a non-negative integer counting
     *         the number of bytes from the beginning of the entity
     *
     * @return  This channel
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IllegalArgumentException
     *          If the new position is negative
     * @throws  IOException
     *          If some other I/O error occurs
     */
    SeekableByteChannel position(long newPosition) throws IOException;

    /**
     * Returns the current size of entity to which this channel is connected.
     *返回通道连接实体的size
     * @return  The current size, measured in bytes
     *
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IOException
     *          If some other I/O error occurs
     */
    long size() throws IOException;

    /**
     * Truncates the entity, to which this channel is connected, to the given
     * size.
     *压缩通道连接的实体到指定的size
     * <p> If the given size is less than the current size then the entity is
     * truncated, discarding any bytes beyond the new end. If the given size is
     * greater than or equal to the current size then the entity is not modified.
     * In either case, if the current position is greater than the given size
     * then it is set to that size.
     *如果给定的size小于实体当前的size,将会压缩实体,丢弃超过新末端的字节。如果
     给定的size大于或等于当前size,实际将不会修改。在其他一些情况下,如果当前的position
     大于给定的size,那么将会设置position。
     * <p> An implementation of this interface may prohibit truncation when
     * connected to an entity, typically a file, opened with the {@link
     * java.nio.file.StandardOpenOption#APPEND APPEND} option.
     *当连接一个实体时,具体接口的实现也许会禁止压缩实体,比如以StandardOpenOption#APPEND
     配置选项打开的文件。
     * @param  size
     *         The new size, a non-negative byte count
     *
     * @return  This channel
     *
     * @throws  NonWritableChannelException
     *          If this channel was not opened for writing
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IllegalArgumentException
     *          If the new size is negative
     * @throws  IOException
     *          If some other I/O error occurs
     */
    SeekableByteChannel truncate(long size) throws IOException;
}
分享到:
评论

相关推荐

    memoryfilesystem:JSR-203文件系统的内存中实现

    SeekableByteChannel FileChannel AsynchronousFileChannel InputStream OutputStream BasicFileAttributeView , BasicFileAttributes DosFileAttributeView , DosFileAttributes PosixFileAttributeV

    99-智慧园区数据平台方案.pptx

    99-智慧园区数据平台方案.pptx

    node-v12.11.1-x86.msi

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    基于Springboot+Vue华强北商城二手手机管理系统-毕业源码案例设计.zip

    网络技术和计算机技术发展至今,已经拥有了深厚的理论基础,并在现实中进行了充分运用,尤其是基于计算机运行的软件更是受到各界的关注。加上现在人们已经步入信息时代,所以对于信息的宣传和管理就很关键。系统化是必要的,设计网上系统不仅会节约人力和管理成本,还会安全保存庞大的数据量,对于信息的维护和检索也不需要花费很多时间,非常的便利。 网上系统是在MySQL中建立数据表保存信息,运用SpringBoot框架和Java语言编写。并按照软件设计开发流程进行设计实现。系统具备友好性且功能完善。 网上系统在让售信息规范化的同时,也能及时通过数据输入的有效性规则检测出错误数据,让数据的录入达到准确性的目的,进而提升数据的可靠性,让系统数据的错误率降至最低。 关键词:vue;MySQL;SpringBoot框架 【引流】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    Excel模版:工资条模板

    Excel工资条模板是一种预先设计好的电子表格文件,主要用于生成和打印员工的工资单,让员工清楚了解自己的工资组成和扣款详情。模板通常包含了以下几个关键部分: 1. **员工信息区**: - 姓名 - 员工编号/工号 - 部门 - 职位 2. **工资构成区**: - 基本工资 - 岗位工资 - 绩效奖金 - 加班工资 - 其他补贴(如交通补贴、餐补、全勤奖等) - 各项津贴(如高温补贴、取暖费等) - 其他应发收入(如年终奖、提成、福利等) 3. **扣款项目区**: - 社保扣款(养老保险、医疗保险、失业保险、工伤保险、生育保险) - 住房公积金 - 个人所得税 - 其他扣款(如迟到、旷工、违规罚款等) - 预借还款(如有) 4. **工资结算区**: - 应发工资总额 - 扣款总额 - 实发工资 5. **备注栏**: - 用于标注本月工资的特殊情况说明,如请假、调休、加班等情况。 6. **签名栏**: - 供员工确认工资数额无误后签名,也可以

    29-【智慧城市与政府治理分会场】10亿大数据助推都市治理-30页.pdf

    29-【智慧城市与政府治理分会场】10亿大数据助推都市治理-30页.pdf

    基于Springboot+Vue的租房管理系统-毕业源码案例设计.zip

    网络技术和计算机技术发展至今,已经拥有了深厚的理论基础,并在现实中进行了充分运用,尤其是基于计算机运行的软件更是受到各界的关注。加上现在人们已经步入信息时代,所以对于信息的宣传和管理就很关键。系统化是必要的,设计网上系统不仅会节约人力和管理成本,还会安全保存庞大的数据量,对于信息的维护和检索也不需要花费很多时间,非常的便利。 网上系统是在MySQL中建立数据表保存信息,运用SpringBoot框架和Java语言编写。并按照软件设计开发流程进行设计实现。系统具备友好性且功能完善。 网上系统在让售信息规范化的同时,也能及时通过数据输入的有效性规则检测出错误数据,让数据的录入达到准确性的目的,进而提升数据的可靠性,让系统数据的错误率降至最低。 关键词:vue;MySQL;SpringBoot框架 【引流】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    线路工区光缆中断抢险预案.docx

    5G通信行业、网络优化、通信工程建设资料。

    299-教育数据资产管理平台及配套解决方案.pptx

    299-教育数据资产管理平台及配套解决方案.pptx

    太戈编程第345题答案

    abababababababab

    基于STM32F103C8单片机设计-旋转编码器数码管显示程序KEIL工程源码.zip

    STM32学习软件编程资料,STM32F103C8单片机经典外设应用设计实例软件源代码,KEIL工程文件,可供学习参考。

    5GKPI指标定义.pptx

    5G通信行业、网络优化、通信工程建设资料。

    全业务端到端-L2题库.xlsx

    5G通信行业、网络优化、通信工程建设资料

    3M 轨道砂光机精英系列说明书

    3M 轨道砂光机精英系列说明书

    基于Springboot+Vue教师工作量管理系统-毕业源码案例设计.zip

    网络技术和计算机技术发展至今,已经拥有了深厚的理论基础,并在现实中进行了充分运用,尤其是基于计算机运行的软件更是受到各界的关注。加上现在人们已经步入信息时代,所以对于信息的宣传和管理就很关键。系统化是必要的,设计网上系统不仅会节约人力和管理成本,还会安全保存庞大的数据量,对于信息的维护和检索也不需要花费很多时间,非常的便利。 网上系统是在MySQL中建立数据表保存信息,运用SpringBoot框架和Java语言编写。并按照软件设计开发流程进行设计实现。系统具备友好性且功能完善。 网上系统在让售信息规范化的同时,也能及时通过数据输入的有效性规则检测出错误数据,让数据的录入达到准确性的目的,进而提升数据的可靠性,让系统数据的错误率降至最低。 关键词:vue;MySQL;SpringBoot框架 【引流】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    2023年亚太杯A题附件一,苹果图像数据集

    2023年亚太杯A题附件一,苹果图像数据集

    移动代维发电系统考试L2.xlsx

    5G通信、网络优化与通信建设

    59-《煤矿测量规程(1989版)》150.pdf

    59-《煤矿测量规程(1989版)》150.pdf

    施工现场安全技术交底模板.doc

    5G通信行业、网络优化、通信工程建设资料。

Global site tag (gtag.js) - Google Analytics