• 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

SimpleMagic

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For posterity I've recently finished v1 of my SimpleMagic java package which reads the Unix magic(5) config files to support content-type detection.

More details, javadocs, documentation, source, etc. can be found at http://256.com/sources/simplemagic/
 
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Congratulation Gray,

Great work!

How do envisage using this in conjunction with uploading a file. One stream is needed to download the stream to a file, and it seems another stream is required to use ContentInfoUtil to match the content info?

I played around using the code below


and found that using that same inputStream to write to file actually corrupted that file. So somehow the streams need to be copied.

As I am not fully across inputStreams, any suggestesion?

Thanks

Marten
 
marten koomen
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, while I am at it, is there an easy way to match the found content type with the file extension?

Cheers

Marten
 
Gray Watson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Marten:

How do envisage using this in conjunction with uploading a file. One stream is needed to download the stream to a file, and it seems another stream is required to use ContentInfoUtil to match the content info?



Right. Without using the wrapper, SimpleMagic will read in from the stream. I've just added to the repo a ContentInfoInputStreamWrapper class which you can read through that gives you the content information about the first bytes that were read.

is there an easy way to match the found content type with the file extension?



I've also just added a mapping from extension to the internal types. This is very limited right now. Take a look at ContentType code. I'd be happy to add a boatload of more entries.

Let me know if you've like me to push out 1.1 or if you can work from git directly.
gray
 
marten koomen
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gray

This works a treat, and will be of value for all Java developers that deal with unknown file types.

Will play around more when I am in production!

Cheers

Marten

 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic