当前位置: 首页>>代码示例>>Java>>正文


Java ByteChannel.isOpen方法代码示例

本文整理汇总了Java中java.nio.channels.ByteChannel.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java ByteChannel.isOpen方法的具体用法?Java ByteChannel.isOpen怎么用?Java ByteChannel.isOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.ByteChannel的用法示例。


在下文中一共展示了ByteChannel.isOpen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readFromChannel

import java.nio.channels.ByteChannel; //导入方法依赖的package包/类
protected void readFromChannel(ByteChannel sc) {
    int len = 0;
    ByteBuffer inputBuffer = inBuf; // save a local reference just in case it gets nulled out.

    // TODO: probably need some type of synchronization on the input
    // buffer because it gets nulled out in closeComplete due to
    // timeout and then can potentially cause a crash here.
    if (sc.isOpen() && state != State.CLOSED && inputBuffer != null) {
        try {
            len = sc.read(inputBuffer);
        } catch (IOException e) {
            LOG.trace("readFromChannel: exception on read on port " + localPort, e);
            len = -1;
        }

        if (LOG.isTraceEnabled()) {
            LOG.trace("readFromChannel(" + len + " bytes) from port " + localPort);
        }

        if (len >= 0) {
            addToBuffer(bytes, len);
            inBuf.clear();
        } else if (len < 0) {
            closeComplete();
        }
    } else if (LOG.isTraceEnabled()) {
        LOG.trace(MessageFormat.format("readFromChannel: Looks like connection is closed for port {0}, sc.isOpen()={1}, state={2}, inputBuffer={3}", localPort, sc.isOpen(), state, inputBuffer));
    }
}
 
开发者ID:jyeary,项目名称:dnsjnio,代码行数:30,代码来源:Connection.java

示例2: valid

import java.nio.channels.ByteChannel; //导入方法依赖的package包/类
/**
 * This methods tests whether or not this object represents a valid open
 * native file handle.
 *
 * @return <code>true</code> if this object represents a valid
 * native file handle, <code>false</code> otherwise
 */
public boolean valid ()
{
  ByteChannel c = channel;
  return (c != null) && (c.isOpen());
}
 
开发者ID:vilie,项目名称:javify,代码行数:13,代码来源:FileDescriptor.java


注:本文中的java.nio.channels.ByteChannel.isOpen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。