So are you saying that you don't want the WriteListener and ReadListener
but more the APIs like the NIO2 as you suggest below? Also would you add
them to the InputStream and also create a ServletWriter as Shing Wai
suggested earlier?
- Rajiv
On 9/14/11 5:46 PM, Greg Wilkins wrote:
> Here is a suggestion of how we could add jdk7 inspired reads to the
> ServletInputStream, but also allow the buffer pre-allocation to be
> avoided.
>
> interface ByteBufferReference
> {
> ByteBuffer getBuffer();
> }
>
> abstract class ServletInputStream
> {
> ...
> abstract Future<Integer> read(ByteBuffer dst);
> abstract Future<Integer> read(ByteBufferReference dst);
> abstract<A> void read(ByteBuffer dst, A attachment,
> CompletionHandler<Integer,? super A> handler);
> abstract<A> void read(ByteBufferReference dst, A attachment,
> CompletionHandler<Integer,? super A> handler);
> }
>
> Simple usage would be possible with the preallocation provided by asDest:
>
> ServletInputStream in=request.getInputStream();
> byte[] buf = new byte[4096];
> Future<Integer> result = in.read(ByteBuffer.wrap(buf,0,buf.length))
>
> // do something else....
>
> result.get(10,TimeUnit.SECONDS);