本文整理汇总了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));
}
}
示例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());
}