billroper: (Default)
[personal profile] billroper
For the test project that I'm working on, I needed to take our binary data and present it in XML in exactly the format that we currently use, except that I had to do it in Java.

Ok, I can make that happen:

  • Open the document file with Apache POI.
  • Write the header for the XML document with the StAX XMLStreamWriter.
  • Write the header for a stream to the XML document with the XMLStreamWriter.
  • Open a stream from the document and read it into a byte array.
  • Compress it with the Deflater class.
  • Write the compressed and uncompressed length of the byte array to the XML document with the XMLStreamWriter.
  • Wrap the resulting compressed byte array in a ByteArrayInputStream.
  • Wrap that in a Base64InputStream to encode it.
  • Wrap that in a InputStreamReader to convert it to characters.
  • Now read characters from the InputStreamReader and write them out to the XMLStreamWriter, wrapped in an opening and closing tag.
  • Repeat until all streams are in the XML stream.

    I had to play a few games with the property sets, because I had used a different method to put those into the original XML response, but I eventually sorted that out.

    This is obviously non-optimum, because I really don't want to have to have both the compressed and uncompressed versions of the stream in memory at the same time, but since the current XML response is formatted that way, we'll live with it for the time being.

    Whee!
  • This account has disabled anonymous posting.
    If you don't have an account you can create one now.
    HTML doesn't work in the subject.
    More info about formatting

    If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

    Profile

    billroper: (Default)
    billroper

    June 2025

    S M T W T F S
    1 2 3 4567
    891011121314
    15161718192021
    22232425262728
    2930     

    Most Popular Tags

    Style Credit

    Expand Cut Tags

    No cut tags
    Page generated Jun. 5th, 2025 07:22 am
    Powered by Dreamwidth Studios