Java code to decompress/extract Remedy attachments without AR Server

Version 8
    Share This:

    BMC have already published a knowledge article with code examples to extract attachments using VC++/VB/.NET  (https://kb.bmc.com/infocenter/index?page=content&id=KA289276 ).

     

    Here is some Java code (it wont compile on its own) to decompress a Remedy attachment in a database without an AR Server.

    This may be useful for example if using a reporting/archive database that has Remedy data but no active server.

     

    It assumes you have already read the code into a byte[] array:


    The ARDecompressor class (and related ARCompressor class ) is in arapiNN.jar (eg arapi75.jar)

     

    import com.bmc.arsys.arcompress.ARDecompressor;

     

    ARDecompressor arDecompressor;

     

    byte[] decompress(byte[] dbinput) {

    ...

         arDecompressor = new ARDecompressor();

         arDecompressor.setInput(dbinput);

         byte[] output = arDecompressor.inflate();

         arDecompressor.end();

     

         return output;

    }

     

    To initially read the compressed attachment using jdbc (assuming your query is in a resultset rs ) use something like below then decompress with code above ...

     

    // Exception handling omitted.

    // Result is initialized with 0 length and grows dynamically.

    // Alternatively just use the uncompressed length in the CO<nnnn> field of the BC table.

    byte[]result = new byte[0];

    byte[] buf = new byte[BUFFER_SIZE];

    InputStream is = rs.getBinaryStream(columnNumberForAttachment);

    while(true) {

         int blen = is.read(buf);

     

         if (blen <= 0 ) break; // no more data


          // newResult = result append buf -

          // I suspect there may be better ways to append the byte arrays!

          byte[] newResult = new byte[result.length + blen];

     

          System.arraycopy(result, 0, newResult, 0, result.length);

          System.arraycopy(buf, 0, newResult, result.length, blen);


          result = newResult;

    }

    is.close();

    rs.close();

     

    return result;