Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:55:10+00:00 2026-06-13T02:55:10+00:00

I have a ServerResource which responds to GET requests by sending binary data back.

  • 0

I have a ServerResource which responds to GET requests by sending binary data back. The issue is that the source of the binary data will be downloaded asynchronously via a separate REST call (probably via HttpAsyncClient). Is it possible to create a Representation that I can feed data to as it arrives from the async download? I need to be able to do it without blocking any threads, so some sort of NIO solution is required.

I suspect I can do this with WriteableRepresetation, but I’m not exactly sure how as the documentation says

For this you just need to create a subclass and override the abstract Representation.write(WritableByteChannel) method. This method will later be called back by the connectors when the actual representation’s content is needed.

implying that when the method is called, all of the content must already be available.

I’m using v2.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:55:11+00:00Added an answer on June 13, 2026 at 2:55 am

    After playing around with it for a bit, it looks like this is possible using a ReadableRepresentation. I dont know if there is a better way to create the ReadableByteChannel than using a Pipe or not, but that’s the only way I saw without having to implement my own Channel.

    private static final byte[] HELLO_WORLD = "hello world\n".getBytes(Charsets.UTF_8);
    
    public static class HelloWorldResource extends ServerResource {
        @Get
        public Representation represent() throws Exception {
            final Pipe pipe = Pipe.open();
    
            // this simulates another process generating the data
            Thread t = new Thread(new Runnable() {
                private final ByteBuffer buf = ByteBuffer.allocate(1);
                private final Pipe.SinkChannel sink = pipe.sink();
    
                private int offset = 0;
    
                @Override
                public void run() {
                    while (offset < HELLO_WORLD.length) {
                        try {
                            buf.clear();
                            buf.put(HELLO_WORLD[offset++]);
                            buf.flip();
    
                            while (buf.hasRemaining()) {
                                sink.write(buf);
                            }
    
                            Thread.sleep(500);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
    
                    try {
                        sink.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.setDaemon(true);
            t.start();
    
            return new ReadableRepresentation(pipe.source(), MediaType.TEXT_PLAIN);
        }
    }
    
    public static class HelloWorldApplication extends Application {
        @Override
        public synchronized Restlet createInboundRoot() {
            Router router = new Router(getContext());
            router.attach("/hello", HelloWorldResource.class);
    
            return router;
        }
    }
    
    public static void main(String[] args) throws Exception {
        Component component = new Component();
        component.getDefaultHost().attach("", new HelloWorldApplication());
    
        Server server = component.getServers().add(Protocol.HTTP, 8090);
    
        component.start();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have two tables say ABC and XYZ and contain one column which data will
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
Have an issue with marshall and unmarshall readers and writers. So here it is.
I have a Rails 2.3.x app that implements the act_as_authentic in User model and
Have a simple form that has a PictureBox in one location. I want to
i have in my localhost:8111 a restlet app running. This app have a ServerResource

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.