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


Java ByteChannel.close方法代码示例

本文整理汇总了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();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:NioProcessor.java

示例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;
}
 
开发者ID:skaterkamp,项目名称:md380codeplug-tool,代码行数:35,代码来源:RDTFactory.java

示例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;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:SocketChannelIOHelper.java


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