Not every format supports every operation. Some formats can only be read, for example. The FileTypeFeatureSupport class describes which features are available for a file type:
Each feature has a SupportLevel: Supported, PartiallySupported or NotSupported.
The getSupportedFileTypeFeatures method has three overloads: it accepts a FileType, a file extension, or no arguments to return the whole matrix.
advanced_usage.GetSupportedFileTypeFeatures
publicclassGetSupportedFileTypeFeatures{publicstaticvoidrun(){// Get the support matrix for a specific file type
FileTypeFeatureSupportpdf=FileTypeFeatureSupport.getSupportedFileTypeFeatures(FileType.PDF);printFeatures(pdf);// ... or look it up by file extension
FileTypeFeatureSupportogg=FileTypeFeatureSupport.getSupportedFileTypeFeatures(".ogg");printFeatures(ogg);// Get the whole matrix
Map<FileType,FileTypeFeatureSupport>matrix=FileTypeFeatureSupport.getSupportedFileTypeFeatures();System.out.println(String.format("Total file types described: %d",matrix.size()));}privatestaticvoidprintFeatures(FileTypeFeatureSupportsupport){System.out.println(String.format("%s (%s): %s",support.getExtension(),support.getFormatFamily(),support.getDescription()));for(FeatureSupportfeature:support.getFeatures()){System.out.println(String.format(" %s: %s",feature.getFeature(),feature.getLevel()));}}}
The following helper checks whether a file can be edited before you try to update it:
For example, canEdit(".docx") returns true and canEdit(".gz") returns false.
Note
For an extension that is not registered, getSupportedFileTypeFeatures(String) throws java.util.NoSuchElementException instead of returning null. Catch the exception if the extension comes from user input.
More resources
Advanced usage topics
To learn more about library features and get familiar how to manage metadata and more, please refer to theadvanced usage section.
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: