Re: Useful class for binary data storate and manipulation



nooneinparticular314159@xxxxxxxxx wrote:

> I'm trying to decide on a structure to store Message Data. A message
> contains binary data of arbitrary format and length. I've created a
> Message object, which contains a MessageLength, and needs to contain
> some sort of array of bytes containing whatever the message is. (I
> don't want to use a string, in case the message is binary data.) There
> is a BitSet object, which I am using for now to contain 160 byte
> signature data, but it seems very inefficient to use that for a
> message, because you have to set bits individually. Array has the same
> problem - you have to set one element at a time. Same with ArrayList.
> I suppose that I could store it in an array, and then read out the bits
> into something else for network or signing operations, but that seems
> kludgy. ArrayList lets you trim the ArrayList capacity to the size of
> the contents, but again, reading data in bit for bit seems inefficient.
>
> What kind of object can I use to store binary data of arbitrary length
> and structure? I would prefer for it to have an easy way to read data
> into it or write or print data from it. It should be able to reduce
> its size to the size of the actual data, but grow if needed. It should
> also be able to return data at a certain offset from the beginning, or
> in a certain range of bits. Clonability is preferable to. It doesn't
> need any other functionality (I think).
>
> Any ideas?
>
> Thanks!

My preference for this type of work is ByteBuffer. It's basically a wrapper
class which provides a simplified way of reading and writing arbitrary data
values (including endianness) in a byte array. Typically the byte array
contains a message being created ready for delivery, or an incoming message to
be decoded.

It has no functionality below the byte level, if you need to be able to set
arbitrary bits you'd need to extend it. It has no ability to change the size of
the byte[] buffer which provides the backing storage, but it does keep track of
how much is used.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@xxxxxxxxxxxx
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
.



Relevant Pages

  • Re: Can i improve this function?i need your help...
    ... into an array of byte,fro putting it into a blob field of a db mysql. ... why do you want to read in a txt file as /binary/ object, and store it ... (the binary data is in the bytemybytes afterwards). ...
    (comp.lang.java.programmer)
  • Re: Windows Regitry - Encryption Key storage
    ... Yeah I tried converting that into binary data but somehow the exact ... > convert the string to byte array and use it. ... > create a binary registry key and will store all the data you need. ...
    (microsoft.public.dotnet.general)
  • Re: INI file and NUM files
    ... We don't know how this binary data is structured... ... You might consider the CFile code I posted in this thread. ... If you want to store several instances of the same data structure, ... instances in the array. ...
    (microsoft.public.vc.mfc)
  • Re: Manipulating binary data
    ... way to go (as I guess it's just dealing with binary data as a 2d array ... modelling the data as a rectangular image) then, why not just store the ... instead of storing a 3x3 array of data as this: ...
    (comp.lang.php)
  • Re: Finding the nearest match without reusing results
    ... comparing an array with a value generates an array of Trues and ... Any diff with wrong State or with used Store is implicitly zeroed out. ... Each must be larger than the absolute value of the maximum Sales ... go.....it just needs to return the closest match. ...
    (microsoft.public.excel.programming)