本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.capacity方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.capacity方法的具体用法?Java IoBuffer.capacity怎么用?Java IoBuffer.capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.buffer.IoBuffer
的用法示例。
在下文中一共展示了IoBuffer.capacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
* Writes <code>data</code> {@link IoBuffer} to the <code>buf</code>
* {@link IoBuffer} which buffers write requests for the
* <code>session</code> {@ link IoSession} until buffer is full
* or manually flushed.
*
* @param session the session where buffer will be written
* @param data the data to buffer
* @param buf the buffer where data will be temporarily written
*/
private void write(IoSession session, IoBuffer data, IoBuffer buf) {
try {
int len = data.remaining();
if (len >= buf.capacity()) {
/*
* If the request length exceeds the size of the output buffer,
* flush the output buffer and then write the data directly.
*/
NextFilter nextFilter = session.getFilterChain().getNextFilter(this);
internalFlush(nextFilter, session, buf);
nextFilter.filterWrite(session, new DefaultWriteRequest(data));
return;
}
if (len > (buf.limit() - buf.position())) {
internalFlush(session.getFilterChain().getNextFilter(this), session, buf);
}
synchronized (buf) {
buf.put(data);
}
} catch (Throwable e) {
session.getFilterChain().fireExceptionCaught(e);
}
}