File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Get a content type from a byte array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get a content type from a byte array?" Watch "Get a content type from a byte array?" New topic
Author

Get a content type from a byte array?

david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
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

Joined: Jun 28, 2010
Posts: 98
Use the java.io.ByteArrayInputStream ..

just my thoughts
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
david arnold
Ranch Hand

Joined: Apr 10, 2009
Posts: 133
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

Joined: Apr 17, 2002
Posts: 25
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get a content type from a byte array?