Results 1 to 2 of 2
  1. #1
    dfens is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default dynamically expanding byte container?

    Hello everyone,
    Imagine this scenario:

    You have a message which you receive as blocks of bytes. The total size of the message is unknown from the start but is indicated to you in the last block (imagine with EOF).
    I cannot use a byte array of fixed size because the max size is unknown from the start. I need something that can EXPAND DYNAMICALLY.
    There is something called ByteBuffer that could probably be suited for this. Any other ideas/recommendations?

    Also...imagine these messages have an ID attached to them, and that many are sent simultaneously, that is: they come intermigled (mixed). What would you do to keep them separated?

    Thanks for any help you can provide!
    Alex

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Quote Originally Posted by dfens View Post
    Hello everyone,
    Imagine this scenario:

    You have a message which you receive as blocks of bytes. The total size of the message is unknown from the start but is indicated to you in the last block (imagine with EOF).
    I cannot use a byte array of fixed size because the max size is unknown from the start. I need something that can EXPAND DYNAMICALLY.
    There is something called ByteBuffer that could probably be suited for this. Any other ideas/recommendations?

    Also...imagine these messages have an ID attached to them, and that many are sent simultaneously, that is: they come intermigled (mixed). What would you do to keep them separated?

    Thanks for any help you can provide!
    Alex
    This is off the top of my head, and of course subject to whatever specific requirements you have and what you're actually doing with all this stuff.

    Assuming a single message is coming through a single point (ie it isn't split amongst threads), you have an id so you can use a HashMap, or similar, with the id as key, and something to hold the bytes as a value. Add each block to this "something". This something needs to be able to point out when it is finished (ie it has encountered the EOF), so that whatever needs to be done to the bytes can be done, and so it can be removed from the Map, otherwise it'll simply fill up.

    As I say above, though, this is off the top of my head, so may be completely rubbish.

Similar Threads

  1. [SOLVED] Creating an auto-expanding JTextArea
    By Singing Boyo in forum New To Java
    Replies: 12
    Last Post: 06-10-2009, 01:31 AM
  2. [SOLVED] JList Expanding when not all contents visible
    By Singing Boyo in forum New To Java
    Replies: 8
    Last Post: 06-01-2009, 05:29 AM
  3. [SOLVED] Prevent JTextField from Expanding Within JFrame
    By Singing Boyo in forum New To Java
    Replies: 5
    Last Post: 05-15-2009, 02:00 AM
  4. Replies: 3
    Last Post: 04-21-2009, 11:01 PM
  5. Collapsing/Expanding() All nodes in a TreeMenu using javascript
    By Hadley in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 01-30-2009, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •