public OutputStream asOutputStream() {
        if ( tmp != null )
            throw new RuntimeException("can create Input/OutputStream only once");
        tmp = new byte[1];
        return new OutputStream() {

            @Override
            public void write(int b) throws IOException {
                tmp[0] = (byte) b;
                write(tmp, 0, 1);
            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                if ( event == null ) {
                    event = new AsyncFileIOEvent(0,0, ByteBuffer.allocate(len));
                }
                if ( event.getBuffer().capacity() < len ) {
                    event.buffer = ByteBuffer.allocate(len);
                }
                ByteBuffer buffer = event.buffer;
                event.reset();
                buffer.put(b,off,len);
                buffer.flip();
                event = AsyncFile.this.write(event.getNextPosition(), buffer).await();
                if ( event.getRead() != len )
                    throw new RuntimeException("unexpected. Pls report");
            }

            @Override
            public void close() throws IOException {
                AsyncFile.this.close();
            }

        };
    }
public OutputStream asOutputStream ( ) { if ( tmp != null ) throw new RuntimeException ( "can create Input/OutputStream only once" ) ; tmp = new byte [ 1 ] ; return new OutputStream ( ) { @ Override public void write ( int b ) throws IOException { tmp [ 0 ] = ( byte ) b ; write ( tmp , 0 , 1 ) ; } @ Override public void write ( byte [ ] b , int off , int len ) throws IOException { if ( event == null ) { event = new AsyncFileIOEvent ( 0 , 0 , ByteBuffer . allocate ( len ) ) ; } if ( event . getBuffer ( ) . capacity ( ) < len ) { event . buffer = ByteBuffer . allocate ( len ) ; } ByteBuffer buffer = event . buffer ; event . reset ( ) ; buffer . put ( b , off , len ) ; buffer . flip ( ) ; event = AsyncFile . this . write ( event . getNextPosition ( ) , buffer ) . await ( ) ; if ( event . getRead ( ) != len ) throw new RuntimeException ( "unexpected. Pls report" ) ; } @ Override public void close ( ) throws IOException { AsyncFile . this . close ( ) ; } } ; }
return a pseudo-blocking output stream. Note: due to limitations of the current await implementation (stack based),
when writing many files concurrently from a single actor thread don't mix high latency file locations (e.g. remote file systems vs. local)
with low latency ones. If this is required, fall back to the more basic read/write methods returning futures.

@return