Skip to content

Is there a class for buffer storage? maybe like ArrayList?

Rob Jones

Asked Feb 17, 2006, 10:28 PM EST3 answers
Share
LinkedInX
Hi. Say I'm building a ZIP file, the ZIP file has a header of UInt32 0x04034b50 then some 2-byte tags, short 0x0A00, and another short. How can i save these: uint part1=0x04034b50; ushort part2=0x0a00; ushort part3=0; I can't put then into an ArrayList because they are of different type. In the end I want to extract the arraylist and put into a byte[].

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    You could write the values to the byte array using BinaryWriter and MemoryStream. First, create your byte array buffer with some good size. Then create MemoryStream object, and use your buffer as a constructor parameter. Then create BinaryWriter, and pass the memory stream to it.

    Now You can write many sorts of information to the byte array buffer, with BinaryWriter's Write -methods.

    Java
    byte[] buffer = new byte[256];
    
                MemoryStream stream = new MemoryStream(buffer);
    
                BinaryWriter writer = new BinaryWriter(stream);
    
                writer.Write("somevalues");
    0
  • 0
    Happy to hear that your problem got solved :)
    0
  • 1 short reply
    • 0
      cheers, that's it!
      0