javauniverseuniobjects

UniObjects for Java read object code file


I am reading from a UniVerse database using UniObjects for Java using the UniFile.read() method. This is an example of the type of code I use for this.

...
UniFile uFile = uSession.open ("ORDERS");
UniDataSet datasetRequest = getUnidatasetRequest();
UniDataSet datasetResult = uFile.read(datasetRequest);  
...

For most queries this works, but when I try to read an object file (eg SOMEFILE.O), this read truncates the records within the file. I am thinking that the special characters in the object code are causing problems.

Is there a way to read object code records using UniObjects for Java?


Solution

  • This is what we ended up doing:

    I couldn't find a way to make the dataset read the binary code, so I read the items one at a time using a subroutine. Before the items could be read I had to install and run a UniBasic subroutine on the database to encode the item into base 64 using something like this:

    ...
    
    LOOP
        READBLK A.BYTE FROM FILE, 1 THEN NULL ELSE DONE = TRUE
    UNTIL DONE DO
        TO.ENCODE = TO.ENCODE : A.BYTE
    REPEAT
    ENCODE('Base64', 1, TO.ENCODE, 1, RET.VALUE, 1)
    
    ...
    

    This subroutine returned the base 64 encoded item as a Stringto UOJ and then it could be decoded and no data was lost. Here is an example of the Java Code:

    ...
    UniSubroutine readBlkSub = unisession.subroutine(routineName, 4);
    readBlkSub.setArg(0, getNameID());
    readBlkSub.setArg(1, itemName);
    readBlkSub.call();
    final String SUCCESS = "0";
    if (readBlkSub.getArg(3).equals(SUCCESS)) {
        encodedObjectCode = readBlkSub.getArg(2);
        sun.misc.BASE64Decoder decoder = new BASE64Decoder();
        byte[] decodedBytes = decoder.decodeBuffer(encodedObjectCode);
        ...
    }