getData

getData(offset: Integer64;
        length: Integer): Binary;

The getData method of the JadeBytes class returns a number of bytes from the binary content of the receiver starting at an offset specified by the value of the offset parameter and with a size specified by the value of the length parameter.

The value of the offset parameter must be between one and the byte length of the binary content.

The following example shows the use of the getData method.

vars
    bytes : JadeBytes;
begin
    create bytes;
    bytes.setContent("JADE".Binary);
    write bytes.getData(3,2);    // Writes "DE"
epilog
    delete bytes;
end;

The following code example shows the use of the getData method to read a large JadeBytes object in chunks. When the getData method is executed, a shared lock is acquired on the JadeBytes object. It is important to minimize locking activity by bracketing the reading of the chunks between beginLoad and endLoad instructions, which keeps the JadeBytes object locked for the entire read transaction.

vars
    length : Integer64;
    chunkSize : Integer;
    data : Binary;
    offset : Integer;
begin
    length := bytes.getLength;
    chunkSize := 64*1024;
    offset := 1;
    beginLoad;
    while length > 0 do
        if length < chunkSize then
            chunkSize := length.Integer;
        endif;
        data := bytes.getData(offset, chunkSize);
        // process data
        offset := offset + chunkSize;
        length := length - chunkSize;
    endwhile;
    endLoad;
end;