cancel
Showing results for 
Search instead for 
Did you mean: 

Problems converting MdmValue to Binary Object with MDM Java API 2

Former Member
0 Kudos

Hello Developers,

i am haveing problems converting an Binary MdmValue into something that i can write to the Filesystem. I am using the MDMJavaAPI_Ver5.5.42.65 resulting from SP5 Patch 2 Hotfix 4.

I want to retrieve PDFs and Images with the RetrieveBlobCommand and store them on the Filesystem.

The Command is executed and i get the BLOB with:

blobCommand.getBlob();

The debugger shows me that i got a hold on the Objekt as an MultiRegionValue of type BINARY (int 15).

After I got the MdmValue

"test"

i want to cast the object to BinaryValue but I get a java.jang.ClassCastException.

Why do I want to cast the result!? Because I want to use the method

getBytes() 

of the BinaryValue to get the byte[] to write this over OutputStream to Filesystem. Is this the right way or am I on the wrong track?

Here is my coding:


RetrieveBlobCommand blobCommand = new RetrieveBlobCommand(this.caRepositoryConnection);
blobCommand.setTableId(PDFs.TBL);
blobCommand.setSession(this.sRepositorySession);
blobCommand.setRecordId(pdfblobRecord.getId());
try {
	blobCommand.execute();
} catch (CommandException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
MdmValue test = blobCommand.getBlob();
// Will be 15 after execution
int type = test.getType();
// On this line the code crashes with java.lang.ClassCastException
// I don’t see why this happens
BinaryValue bv = (BinaryValue) test;

Has anyone some idea how i can manage to store the retrieved BLOB to the Filesystem?

Any hint is highly appreciated!

THX

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

After a lot of testing finally i found the solution to my problem!


//MDM MULTIREGION VALUE is the result of the getblob method

// Now I get the avalible region codes for the result and store to String[]
String[] regions = ((MultiregionValue) blobCommand.getBlob()).getRegionCodes();

// 1. get the value corresponding to the region code and store as MdmValue
MdmValue test = ((MultiregionValue) blobCommand.getBlob()).getValue(regions[0]);

// 2. Now it is possible to cast to BinaryValue
BinaryValue bv = (BinaryValue) test;			

So my problem is finally solved.

Hope this will help if you have the same problem.

Regards,

Tobi