public abstract class FileTypeRegistry
extends java.lang.Object
Performance notice. There are different rules of file type matching for a file: matching by file name, by extension,
by file content, by custom logic providers and so on. They are all executed by the general methods getFileTypeByFile
,
thus implying that execution of
such methods is as long as the sum of all possible matching checks in the worst case. That includes reading file contents to
feed to all FileTypeRegistry.FileTypeDetector
instances, checking FileTypeIdentifiableByVirtualFile
and so on. Such actions
may lead to considerable slowdowns if used on large VirtualFile
collections, e.g. in
BulkFileListener
implementations.
If it is possible and correct to restrict file type matching by particular means (e.g. match only by file name), it is advised to do so, in order to improve the performance of the check, e.g. use
FileTypeRegistry.getInstance().getFileTypeByFileName(file.getNameSequence())
instead of
file.getFileType()
Also, if you are interested not in getting file type, but rather comparing file type with a known one, prefer using
isFileOfType(VirtualFile, FileType)
, as it is faster than getFileTypeByFile(VirtualFile)
as well.Modifier and Type | Class and Description |
---|---|
static interface |
FileTypeRegistry.FileTypeDetector
Pluggable file type detector by content
|
Modifier and Type | Field and Description |
---|---|
static Getter<FileTypeRegistry> |
ourInstanceGetter |
Constructor and Description |
---|
FileTypeRegistry() |
Modifier and Type | Method and Description |
---|---|
LanguageFileType |
findFileTypeByLanguage(Language language) |
abstract FileType |
findFileTypeByName(java.lang.String fileTypeName)
Finds a file type with the specified name.
|
abstract FileType |
getFileTypeByExtension(java.lang.String extension)
Returns the file type for the specified extension.
|
abstract FileType |
getFileTypeByFile(VirtualFile file)
Returns the file type for the specified file.
|
FileType |
getFileTypeByFile(VirtualFile file,
byte [] content)
Returns the file type for the specified file.
|
FileType |
getFileTypeByFileName(java.lang.CharSequence fileNameSeq)
Returns the file type for the specified file name.
|
abstract FileType |
getFileTypeByFileName(java.lang.String fileName)
Same as getFileTypeByFileName(CharSequence) but receives String parameter.
|
static FileTypeRegistry |
getInstance() |
abstract FileType [] |
getRegisteredFileTypes()
Returns the list of all registered file types.
|
abstract boolean |
isFileIgnored(VirtualFile file) |
boolean |
isFileOfType(VirtualFile file,
FileType type)
Checks if the given file has the given file type.
|
public static Getter<FileTypeRegistry> ourInstanceGetter
public abstract boolean isFileIgnored(VirtualFile file)
public boolean isFileOfType(VirtualFile file, FileType type)
public LanguageFileType findFileTypeByLanguage(Language language)
public static FileTypeRegistry getInstance()
public abstract FileType [] getRegisteredFileTypes()
public abstract FileType getFileTypeByFile(VirtualFile file)
file
- The file for which the type is requested.public FileType getFileTypeByFile(VirtualFile file, byte [] content)
file
- The file for which the type is requested.content
- Content of the file (if already available, to avoid reading from disk again)public FileType getFileTypeByFileName(java.lang.CharSequence fileNameSeq)
fileNameSeq
- The file name for which the type is requested.FileTypes.UNKNOWN
if not found.public abstract FileType getFileTypeByFileName(java.lang.String fileName)
public abstract FileType getFileTypeByExtension(java.lang.String extension)
getFileTypeByFile(VirtualFile)
extension
- The extension for which the file type is requested, not including the leading '.'.UnknownFileType.INSTANCE
if corresponding file type not foundpublic abstract FileType findFileTypeByName(java.lang.String fileTypeName)