cancel
Showing results for 
Search instead for 
Did you mean: 

Reading document content in smaller chunks.

amit_wmw
Champ in-the-making
Champ in-the-making
Hello friends,

I want to get contents from repository in smaller chucks, so that it can easily accommodate in a byte array. As reading a document of huge size say 2-3GB and getting all content out of it at a short doesn’t seems to be possible. Do you have sample code with regards to this? Kind if you can share!

Thanks
Amit.
5 REPLIES 5

mrogers
Star Contributor
Star Contributor
You would normally use content streaming for reading the large files.   So you read a chunk of data into your buffer and then repeat until the end of the stream.    What language and environment are you operating in?

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks Rogers! I am working in Java language, in Windows environment.

Currently in my code I am getting the content by reading file via contentService.getReader()

#################################################################################################
ContentReader contentReader1 = contentService.getReader(fileRef, ContentModel.PROP_CONTENT);

System.out.println("Reading content" + contentReader1.getContentString());
#################################################################################################

So, if have to use content streaming instead(as you suggested), what all things I need to do? Please suggest.

Thanks in advance
Amit.

amit_wmw
Champ in-the-making
Champ in-the-making
Dear,

Any answers, anybody? Or can anyone at least share piece of sample code of how to use content streaming for reading the large files?

Thanks in advance.

Amit.

mrogers
Star Contributor
Star Contributor
The contentReader has a getContentInputStream()  method.

Pretty much any Java text book will explain how to use InputStreams

Here's something I found on the web
http://docs.rinet.ru/JWP/ch11.htm#InputStream

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks again Rogers!

Well instead, how about using "DownloadContentServlet" class of Alfresco API? Mean its mentioned (in comments)over there as:

"get the content and stream directly to the response output stream, assuming the repo is capable of streaming in chunks, this should allow large files to be streamed directly to the browser response stream.".

So my question now is, should I use this class considering alfresco to be capable of streaming data in chunks providing output? Please suggest.

regards-
Amit