Re: Useful class for binary data storate and manipulation
- From: Nigel Wade <nmw@xxxxxxxxxxxx>
- Date: Mon, 24 Oct 2005 10:09:59 +0100
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
.
- Prev by Date: Artificial Intelligence
- Next by Date: Ant help - Javadoc
- Previous by thread: Re: Useful class for binary data storate and manipulation
- Next by thread: [Newbie] Simple multi-file program won't compile
- Index(es):
Relevant Pages
|