Bill Roper (billroper) wrote,
Bill Roper

The Data Goes Round and Round

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.

  • Tags: computers, java, musings, work

    • Long Day

      It was a long day, but the refactoring that I started yesterday is done, at least for a bit. Tomorrow, it's back to debugging. :)

    • The X-Refactor

      I actually don't so much mind refactoring code, as long as I am doing something that will improve the code base. For instance, today I worked with…

    • Sofa, So Good

      They were having one of their periodic sales at La-Z-Boy this weekend. Given the condition of the sleeper sofa in the living room and the couch in…

    • Post a new comment


      Anonymous comments are disabled in this journal

      default userpic

      Your reply will be screened

      Your IP address will be recorded