HI,

i integrating a servlet based application with Akka Streams.

I need implement a process for take in input a servlet input stream, parse 
request with Commons FileUpload and produce a response.


class MyReadListener implements ReadListener
{
    private final ServletInputStream servletInputStream;
    
    private Promise<Optional<ByteString>> promise = 
FutureConverters.promise();
    
    public My(ServletInputStream servletInputStream)
    {
        this.servletInputStream = servletInputStream;
        
        servletInputStream.setReadListener(this);
    }

    @Override
    public void onDataAvailable() throws IOException
    {
        readData();
    }
    
    private void readData() throws IOException
    {
        if (promise.isCompleted())
        {    
            return;
        }
        
        if (servletInputStream.isFinished())        
        {
            promise.success(Optional.empty());
        }
        else
        {
            if (servletInputStream.isReady())
            {
                if (!servletInputStream.isFinished())
                {
                    byte[] data = new byte[16];
                    int count;
                    count = servletInputStream.read(data);
                    System.out.println(count);
                    promise.success(Optional.of(ByteString.fromArray(data, 
0, count)));
                }
            }
        }
        
    }

    @Override
    public void onAllDataRead() throws IOException
    {
    }

    @Override
    public void onError(Throwable t)
    {
        promise.failure(t);
    }
    
    public Promise<Optional<ByteString>> cs()
    {
        try
        {
            readData();
            
            return promise;
        }
        catch (IOException e)
        {
            return promise.failure(e);
        }
        finally
        {
            promise = FutureConverters.promise();
        }
    }
}


...


AsyncContext ctx = req.startAsync(req, resp);

        ServletInputStream servletInputStream = 
ctx.getRequest().getInputStream();
        
        
        Source<ByteString, NotUsed> src1 = Source.unfoldResourceAsync(
                () -> FutureConverters.toJava(Futures.successful(new 
MyReadListener(servletInputStream))),
                n -> FutureConverters.toJava(n.cs().future()),
                n -> {
                    return 
FutureConverters.toJava(Futures.successful(Done.getInstance()));
                });

Now, how I can convert the stream of ByteString in a InputStream parseable 
by Commons FileUpload Library?

Thanks in advance

Stefano

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to