Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get a content type from a byte array?

 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got a byte array through web service which contains a file data. I need to get the content/mime type first, then write byte to a ServletOutputStream, how should I do that ?

Thanks.
 
dileep keely
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the java.io.ByteArrayInputStream ..

just my thoughts
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't the webservice provide you with that information? There is no handy way to determine which kind of file/mine-type is in a file without meta-data. Although there are libraries that try to analyse the document and provide you with a mime-type.
 
david arnold
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Web service may not contain the file name/type which I got this problem.

Anyway. thank you dileep and wouter for kind help!!

Regards,
 
Mike Cronin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I realize this is kind of late, but I'm trying to do the same thing and found the following...

http://download.oracle.com/javaee/5/api/javax/mail/util/ByteArrayDataSource.html

Presently, I have to go a different route, but thought this could help someone else.

Regards,

Mike

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic