Every MIME type, listed in one convenient table. Suffixes applicable, Media type and subtype(s).3dm, x-world/x-3dmf.3dmf, x-world/x-3dmf. MimeType – an actual MIME type holder – and tion. MimetypesFileTypeMap – class whose instance can resolve MIME type as String for a file. setDataHandler(new DataHandler(new ByteArrayDataSource(s, mimetype))); } catch At this point the datasource is actually a {@link ByteArrayDataSource}.

Author: Fenrirg Tell
Country: South Africa
Language: English (Spanish)
Genre: Life
Published (Last): 23 July 2015
Pages: 395
PDF File Size: 10.7 Mb
ePub File Size: 5.14 Mb
ISBN: 407-2-58854-612-5
Downloads: 28107
Price: Free* [*Free Regsitration Required]
Uploader: Tami

Java Examples for rayDataSource

It is, however, super simple to add any content type you may need:. To fetch mime type for a file, you would simply use Files and do this in your code:.

To fetch mime type byteafraydatasource a file, you would simply use Files and do this in your code: Lee Theobald 4, 11 40 The implementation in this class calls getContentType f. For this particular case, I don’t need one yet.

All had extension renamed. Post as a guest Name. FileTypeDetectorwhich defines a standard API for determining a file type in implementation specific way. Not every Java program is required to be portable. However, as suggested by mimme comment above, the built-in table of mime-types is quite limited, not including, for example, MSWord and PDF.

Vazgen Torosyan 6 Post Your Answer Discard By clicking “Post Your Answer”, you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policyand that your continued use of the website is subject to these policies. It is, however, super simple to add any content type you may need: Unfortunately, as the javadoc for getContentType File states: Cassio Seffrin 5 9. In the real world, the one where you need TL,DR section, you should find the library with most stars next to it’s name and use it.


Tika should be the answer now. Perfect solution – helped me a lot! Jul 29 ’15 at Look the complete test code Java 7: However, you have this: I tried several ways to do it, including the first ones said by Joshua Fox. The first gave me memory exceptions, the second doesn’t close its streams off properly.

Java Examples for javax.mail.util.ByteArrayDataSource

In some ideal world in a galaxy far, far away, all these libraries which try to solve this file-to-mime-type problem would simply implement java. Not at all, maybe they have an earlier version of JDK: I used the class that was posted as an answer here: You only need this function public static String getContentType byte[] data, String name It probes the first bytes of the content and returns the content types based on that content and not by file extension. I like to use standard facilities provided by JDK first, and if that doesn’t work, I’ll go and look for something else.


This will work, but is IMO a bad practice as it ties your code to a specific OS and requires the external utility to be present at the system running it. I don’t know if I’m just doing something horribly wrong, but that seems rather terrible.


It was not my system so I didn’t check the JRE or windows version. Returns the MIME type of the file object.

With Apache Tika you need only three lines of code: It only leaves it locked because you’ve left yourself no way to close it. Create file named ‘mime.

To chip in with my 5 cents: More hints are provided at https: First you can check for the mimeType and validate it. I’ve published my SimpleMagic Java package which allows content-type mime-type determination from files and byte arrays.

And for those needing to use this solution within Android, you can simply include the following in the build. The other answers below make light of many dependencies with Tika, but I see none with tika-core.