本文整理汇总了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);
}
});
}
示例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);
}
});
}
示例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);
}
});
}
示例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();
}
}