cancel
Showing results for 
Search instead for 
Did you mean: 

How To Store In to byte[]

Former Member
0 Kudos

Hi Friends,

I have to store a file or document in to byte[] and have to set into RFC. I am able to save the document as resource and To get it back. But i have no idea that how to get this resource into byte[]. Please suggest me the approach i should follow.?

Thanks & Regards

Jeetendra

Accepted Solutions (1)

Accepted Solutions (1)

Abhinav_Sharma
Contributor
0 Kudos

Hello,

You can read byte[] from the resource object that you created.

Suppose resource is of type IWDResource and you want to read it multiple times, then create

byte[] buffer = new byte[1024];

resource.read(true).read(buffer);

pass this buffer to your RFC.

Hope it helps

Abhinav

Former Member
0 Kudos

Hi Abhinav,


byte[] buffer = new byte[1024];    // here How we can determine the exect size of array.?

resource.read(true).read(buffer);

when i am passing this buffer to RFC its throwing null pointer error.

java.lang.NullPointerException: while trying to invoke the method xxxx.com.node_check.node_check_app.comp.wdp.IPrivateNode_check_appCompView$IYsdkprodoccreate_InputElement.setI_Binary_Data(byte[]) of an object returned from xxxxx.com.node_check.node_check_app.comp.wdp.IPrivateNode_check_appCompView$IContextNode.currentYsdkprodoccreate_InputElement()

What may be the Reason.?

Thanks & Regards

Jeetendra

Former Member
0 Kudos

Hi Friends,

Thanks for all your response The problem get solved. i followed following Approach.


                                int c = -1;
				int i = 0;
                               byte[] bArray;
				while ((c = input.read()) != -1) {
					out.write(c);
					i++;
				}
				bArray = new byte<i>;
				for(int j=0;j<=i;j++){
					wdContext.currentContextElement().getResource().read(false).read(bArray);
				}

Thanks & Regards

Jeetendra

Answers (1)

Answers (1)

Former Member
0 Kudos

If I remember correctly, the WDWebResource type can be converted to a File object. Next up just convert the File object to a byte array. Here's the File to byte[] array: [File to Byte Array|http://www.exampledepot.com/egs/java.io/File2ByteArray.html]

Goodluck!

Regards,

Jan