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


Java NIOInputStream类代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.io.NIOInputStream的典型用法代码示例。如果您正苦于以下问题:Java NIOInputStream类的具体用法?Java NIOInputStream怎么用?Java NIOInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doRead

import org.glassfish.grizzly.http.io.NIOInputStream; //导入依赖的package包/类
@Override
protected void doRead(final Action<ByteBuffer> chunkAction) {
  final NIOInputStream in = request.getNIOInputStream();
  in.notifyAvailable(new ReadHandler() {
    @Override
    public void onDataAvailable() throws Exception {
      int bytesRead = -1;
      byte buffer[] = new byte[8192];
      while (in.isReady() && (bytesRead = in.read(buffer)) != -1) {
        chunkAction.on(ByteBuffer.wrap(buffer, 0, bytesRead));
      }
    }

    @Override
    public void onAllDataRead() throws Exception {
      // Unlike Servlet 3.1, there may be remaining data
      onDataAvailable();
      endActions.fire();
    }

    @Override
    public void onError(Throwable t) {
      errorActions.fire(t);
    }
  });
}
 
开发者ID:cettia,项目名称:asity,代码行数:27,代码来源:GrizzlyServerHttpExchange.java

示例2: doRead

import org.glassfish.grizzly.http.io.NIOInputStream; //导入依赖的package包/类
@Override
protected void doRead(final Action<ByteBuffer> chunkAction) {
    final NIOInputStream in = request.getNIOInputStream();
    in.notifyAvailable(new ReadHandler() {
        @Override
        public void onDataAvailable() throws Exception {
            int bytesRead = -1;
            byte buffer[] = new byte[8192];
            while (in.isReady() && (bytesRead = in.read(buffer)) != -1) {
                chunkAction.on(ByteBuffer.wrap(buffer, 0, bytesRead));
            }
        }
        
        @Override
        public void onAllDataRead() throws Exception {
            // Unlike Servlet 3.1, there may be remaining data
            onDataAvailable();
            endActions.fire();
        }
        
        @Override
        public void onError(Throwable t) {
            errorActions.fire(t);
        }
    });
}
 
开发者ID:vibe-project,项目名称:vibe-java-platform,代码行数:27,代码来源:GrizzlyServerHttpExchange.java

示例3: service

import org.glassfish.grizzly.http.io.NIOInputStream; //导入依赖的package包/类
public void service(final Request req, final Response resp) throws Exception {
	// suspend the response, allowing for async processing
	resp.suspend();
	LogManager.getLogger(this).info(String.format("Request: %s, IP %s", req.getRequestURI(), req.getRemoteAddr()));
	int length = req.getContentLength();
	if (length > Server.MAX_POST_SIZE || length < Server.MIN_POST_SIZE){
		m_errorHandler.handleInvalidPost(null, resp, new IllegalArgumentException("Invalid content-length of " + length));
		return; // FIXME- this probably wants to be handled using an error-handling mechanism.
	}
	final ByteBuffer postBytes = ByteBuffer.allocate(req.getContentLength());
	final NIOInputStream in = req.getNIOInputStream();

	in.notifyAvailable(new ReadHandler() {
		
		public void onError(Throwable t) {
			try {
				m_errorHandler.handleInvalidPost(postBytes, resp, t);
			} catch (IOException e) {
				e.printStackTrace(); // FIXME
			}
			resp.resume();
		}
		
		public void onDataAvailable() throws Exception {
			addToBuffer(in, postBytes);
			in.notifyAvailable(this);
		}
		
		public void onAllDataRead() throws Exception {
			addToBuffer(in, postBytes);
			postBytes.flip();									
			m_successHandler.handlePost(postBytes, req, resp);
		}
	});
	
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:37,代码来源:AsyncPostHandler.java

示例4: addToBuffer

import org.glassfish.grizzly.http.io.NIOInputStream; //导入依赖的package包/类
public void addToBuffer(NIOInputStream in, ByteBuffer postBytes){
	Buffer buffer = in.readBuffer();
	ByteBuffer bb = buffer.toByteBuffer();
	try {
		postBytes.put(bb);			
	} finally {
		buffer.tryDispose();
	}
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:10,代码来源:AsyncPostHandler.java


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