We have a requirement where a file will be uploaded to a application (that can be in any format like pdf, txt, doc, img, hmt) and will get stored into Oracle DB as BLOB.
I need to display the contents of that BLOB file as HTML text. Any idea how to do that?
Also the file will be stored in cache for future use. But we do want to use any 3rd party caching tool. How to do it with Java?
A BLOB is actually a bad type for HTML text, as it's meant for binary data (BLOB = Binary Large OBject). A CLOB (Character Large OBject) is a better choice. That would allow you to use character streams (ResultSet.getCharacterStream, Clob.getCharacterStream). Copy the contents of these Readers to a StringWriter, and use its toString method when done to get an HTML String.
But let's assume you can't change the database. Then you must use ResultSet.getBinaryStream or Blob.getBinaryStream. You should wrap the returned InputStream into an InputStreamReader, providing the encoding used. You can then again copy from the InputStreamReader to a StringWriter to get an HTML String.
Edit: or next time I just read your post better. I missed the multiple documents. That makes it complex. You'll need to have code to convert each document type to HTML. For some it's easy; for HTML you don't need to do anything, and for text you only need to wrap it in a <PRE> tag. For others there are more complex solutions. Especially the image can be troublesome, as I don't think you want to have an HTML page with just an <IMG> tag. You'll need to perform OCR to retrieve the text from the image.
I'll move this thread to our Java in General forum as the displaying is going to be the least of your problems.