Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Determine file (image) type from an InputStream  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers....it's me again

Ok, my previous post was about extracting images from an Excel file and then writing them to disk, which I can now do with no problems...except when the image inserted in the Excel file is not supported by Java.

In this situation I can't use the ImageIO.write function because the image type is not known.

Does anyone know of a way to determine the image file type from an InputStream? The thing is, I need to use an InputStream to get the file type because the image itself is not in it's own file, so I can't just use the file extension.

Is this even possible?

Thanks!
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to look into the file headers

A quick reference can be found here

http://www.fastgraph.com/help/image_file_header_formats.html

 
A Shehadi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

But I solved it using Java Mime Magic Library although it's lacking documentation.

To use it you will need the jakarta-oro and commons-loging libraries (I used versions 2.0.8 and 1.1.1 respectively).

It did a pretty good job identifying images embedded in an Excel file (extracted using JExcelApi project library) and read with an InputStream.

Thanks a lot though. I had some issues with an image that JMimeMagic wouldn't detect and I think I'll have to take a look into the link you posted.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!