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


Java StreamSourceChannel.read方法代码示例

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


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

示例1: setup

import org.xnio.channels.StreamSourceChannel; //导入方法依赖的package包/类
public void setup(final StreamSourceChannel channel) {
    Pooled<ByteBuffer> resource = bufferPool.allocate();
    ByteBuffer buffer = resource.getResource();
    try {
        int r = 0;
        do {
            r = channel.read(buffer);
            if (r == 0) {
                channel.getReadSetter().set(this);
                channel.resumeReads();
            } else if (r == -1) {
                stringDone(string.extract());
                IoUtils.safeClose(channel);
            } else {
                buffer.flip();
                string.write(buffer);
            }
        } while (r > 0);
    } catch (IOException e) {
        error(e);
    } finally {
        resource.free();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:StringReadChannelListener.java

示例2: handleEvent

import org.xnio.channels.StreamSourceChannel; //导入方法依赖的package包/类
@Override
public void handleEvent(final StreamSourceChannel channel) {
    Pooled<ByteBuffer> resource = bufferPool.allocate();
    ByteBuffer buffer = resource.getResource();
    try {
        int r = 0;
        do {
            r = channel.read(buffer);
            if (r == 0) {
                return;
            } else if (r == -1) {
                stringDone(string.extract());
                IoUtils.safeClose(channel);
            } else {
                buffer.flip();
                string.write(buffer);
            }
        } while (r > 0);
    } catch (IOException e) {
        error(e);
    } finally {
        resource.free();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:StringReadChannelListener.java

示例3: read

import org.xnio.channels.StreamSourceChannel; //导入方法依赖的package包/类
public void read(StreamSourceChannel channel) {
    try (PooledByteBuffer poolItem = exchange.getConnection().getByteBufferPool().allocate()) {
        ByteBuffer buffer = poolItem.getBuffer();
        int bytesRead;
        while (true) {
            buffer.clear();
            bytesRead = channel.read(buffer);
            if (bytesRead <= 0) break;
            buffer.flip();
            ensureCapacity(bytesRead);
            buffer.get(body, position, bytesRead);
            position += bytesRead;
        }
        if (bytesRead == -1) {
            if (contentLength >= 0 && position < body.length) {
                throw Exceptions.error("body ends prematurely, expected={}, actual={}", contentLength, position);
            } else if (body == null) {
                body = new byte[0]; // without content length and has no body
            }
            complete = true;
            exchange.putAttachment(REQUEST_BODY, new RequestBody(body, null));
        }
    } catch (Throwable e) { // catch all errors during IO, to pass error to action log
        IoUtils.safeClose(channel);
        complete = true;
        exchange.putAttachment(REQUEST_BODY, new RequestBody(null, e));
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:29,代码来源:RequestBodyReader.java

示例4: handleEvent

import org.xnio.channels.StreamSourceChannel; //导入方法依赖的package包/类
@Override
public void handleEvent(StreamSourceChannel channel) {
	if (this.session.isDisconnected()) {
		if (logger.isDebugEnabled()) {
			logger.debug("SockJS sockJsSession closed, closing response.");
		}
		IoUtils.safeClose(this.connection);
		throw new SockJsException("Session closed.", this.session.getId(), null);
	}

	Object pooled = undertowBufferSupport.allocatePooledResource();
	try {
		int r;
		do {
			ByteBuffer buffer = undertowBufferSupport.getByteBuffer(pooled);
			buffer.clear();
			r = channel.read(buffer);
			buffer.flip();
			if (r == 0) {
				return;
			}
			else if (r == -1) {
				onSuccess();
			}
			else {
				while (buffer.hasRemaining()) {
					int b = buffer.get();
					if (b == '\n') {
						handleFrame();
					}
					else {
						this.outputStream.write(b);
					}
				}
			}
		}
		while (r > 0);
	}
	catch (IOException exc) {
		onFailure(exc);
	}
	finally {
		undertowBufferSupport.closePooledResource(pooled);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:46,代码来源:UndertowXhrTransport.java


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