Skip to Content
0
Former Member
Jun 05, 2009 at 12:24 PM

Memory issues while fetching content

24 Views

HI all,

I am using SAP KM Apis. however i am facing some memory issues while using them.

I am using getContent() api on a resource. and then getInputStream on the Icontent object. I am using a ByteArrayOutputStream for writing the data. here is the code snippet:

byte[] buf= new byte[4096];

InputStream inputStream = content.getInputStream();

ByteArrayOutputStream os = new ByteArrayOutputStream(1024)

while ((count = inputStream.read(buf)) != -1)

{

os.write(buf, 0, count);

}

byte[] arr=os.toByteArray();

THis code consuimes a lot of memory . we need to optimize this. we also tried removing BYteArrayOutputSteam and directly read the bytes in chunk :

int n;

do

n = inputStream.read(buf, 0,(int)content.getContentLength());

while (n != -1);

however this approach has not helped us.

please suggest an approach where memory consumption is less and the entire content is fed.

thanks