• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BLOB file contents as HTML text

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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?

Thanks
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic