本文整理汇总了Java中java.nio.channels.ByteChannel.close方法的典型用法代码示例。如果您正苦于以下问题:Java ByteChannel.close方法的具体用法?Java ByteChannel.close怎么用?Java ByteChannel.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.channels.ByteChannel
的用法示例。
在下文中一共展示了ByteChannel.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroy
import java.nio.channels.ByteChannel; //导入方法依赖的package包/类
@Override
protected void destroy(NioSession session) throws Exception {
ByteChannel ch = session.getChannel();
SelectionKey key = session.getSelectionKey();
if (key != null) {
key.cancel();
}
ch.close();
}
示例2: unmarshal
import java.nio.channels.ByteChannel; //导入方法依赖的package包/类
/**
* Read RDT file.
*
* @param file
* @return
*/
public Codeplug unmarshal(Path file) throws IOException {
if (Files.size(file) != RDT_FILE_SIZE) {
throw new IOException("File is corrupted, size not equal to 262709: " + Files.size(file));
}
ByteChannel byteChannel = Files.newByteChannel(file);
ByteBuffer byteBuffer = ByteBuffer.allocate(RDT_FILE_SIZE);
if (RDT_FILE_SIZE != byteChannel.read(byteBuffer)) {
throw new IOException("File not properly read.");
}
byte[] rdtArray = byteBuffer.array();
byteChannel.close();
byte[] header = Arrays.copyOfRange(rdtArray, 0, RDT_PAYLOAD_STARTPOS);
byte[] codeplugBytes = Arrays.copyOfRange(rdtArray, RDT_PAYLOAD_STARTPOS, RDT_PAYLOAD_ENDPOS);
byte[] footer = Arrays.copyOfRange(rdtArray, RDT_PAYLOAD_ENDPOS, RDT_FILE_SIZE);
DeviceFirmwareUpgrade dfu = new DeviceFirmwareUpgrade();
dfu.setDfuHeader(header);
dfu.setDfuFooter(footer);
CodeplugFactory codeplugFactory = new CodeplugFactory(CodeplugType.MD380);
Codeplug codeplug = codeplugFactory.unmarshal(codeplugBytes);
dfu.setCodeplug(codeplug);
return codeplug;
}
示例3: batch
import java.nio.channels.ByteChannel; //导入方法依赖的package包/类
/** Returns whether the whole outQueue has been flushed */
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
ByteBuffer buffer = ws.outQueue.peek();
if( buffer == null ) {
if( sockchannel instanceof WrappedByteChannel ) {
WrappedByteChannel c = (WrappedByteChannel) sockchannel;
if( c.isNeedWrite() ) {
c.writeMore();
return !c.isNeedWrite();
}
return true;
}
} else {
do {// FIXME writing as much as possible is unfair!!
/*int written = */sockchannel.write( buffer );
if( buffer.remaining() > 0 ) {
return false;
} else {
ws.outQueue.poll(); // Buffer finished. Remove it.
buffer = ws.outQueue.peek();
}
} while ( buffer != null );
}
if( ws.isClosed() ) {
synchronized ( ws ) {
sockchannel.close();
}
}
return sockchannel instanceof WrappedByteChannel == true ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
}