Package org.eclipse.rdf4j.common.lang
Class FileFormat
java.lang.Object
org.eclipse.rdf4j.common.lang.FileFormat
- Direct Known Subclasses:
QueryResultFormat
,RDFFormat
Abstract representation of a file format. File formats are identified by a
name
and can have one
or more associated MIME types, zero or more associated file extensions and can specify a (default) character
encoding.- Author:
- Arjohn Kampman
-
Constructor Summary
ConstructorDescriptionFileFormat
(String name, String mimeType, Charset charset, String fileExtension) Creates a new FileFormat object.FileFormat
(String name, String mimeType, Charset charset, Collection<String> fileExtensions) Creates a new FileFormat object.FileFormat
(String name, Collection<String> mimeTypes, Charset charset, Collection<String> fileExtensions) Creates a new FileFormat object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares FileFormat objects based on theirname
, ignoring case.Get the (default) charset for this file format.Gets the default file name extension for this file format.Gets the default MIME type for this file format.Gets the file format's file extensions.Gets the file format's MIME types.getName()
Gets the name of this file format.boolean
Checks if the FileFormat has a (default) charset.boolean
hasDefaultFileExtension
(String extension) Checks if the specified file name extension matches the FileFormat's default file name extension.boolean
hasDefaultMIMEType
(String mimeType) Checks if the specified MIME type matches the FileFormat's default MIME type.boolean
hasFileExtension
(String extension) Checks if the FileFormat's file extension is equal to the specified file extension.int
hashCode()
boolean
hasMIMEType
(String mimeType) Checks if specified MIME type matches one of the FileFormat's MIME types.static <FF extends FileFormat>
Optional<FF> matchFileName
(String fileName, Iterable<FF> fileFormats) Tries to match the specified file name with the file extensions of the supplied file formats.static <FF extends FileFormat>
Optional<FF> matchMIMEType
(String mimeType, Iterable<FF> fileFormats) Tries to match the specified MIME type with the MIME types of the supplied file formats.toString()
-
Constructor Details
-
FileFormat
Creates a new FileFormat object.- Parameters:
name
- The name of the file format, e.g. "PLAIN TEXT".mimeType
- The (default) MIME type of the file format, e.g. text/plain for plain text files.charset
- The default character encoding of the file format. Specify null if not applicable.fileExtension
- The (default) file extension for the file format, e.g. txt for plain text files.
-
FileFormat
Creates a new FileFormat object.- Parameters:
name
- The name of the file format, e.g. "PLAIN TEXT".mimeType
- The (default) MIME type of the file format, e.g. text/plain for plain text files.charset
- The default character encoding of the file format. Specify null if not applicable.fileExtensions
- The file format's file extension(s), e.g. txt for plain text files. The first item in the list is interpreted as the default file extension for the format.
-
FileFormat
public FileFormat(String name, Collection<String> mimeTypes, Charset charset, Collection<String> fileExtensions) Creates a new FileFormat object.- Parameters:
name
- The name of the file format, e.g. "PLAIN TEXT".mimeTypes
- The MIME type(s) of the file format, e.g. text/plain for theplain text files. The first item in the list is interpreted as the default MIME type for the format. The supplied list should contain at least one MIME type.charset
- The default character encoding of the file format. Specify null if not applicable.fileExtensions
- The file format's file extension(s), e.g. txt for plain text files. The first item in the list is interpreted as the default file extension for the format.
-
-
Method Details
-
getName
Gets the name of this file format.- Returns:
- A human-readable format name, e.g. "PLAIN TEXT".
-
getDefaultMIMEType
Gets the default MIME type for this file format.- Returns:
- A MIME type string, e.g. "text/plain".
-
hasDefaultMIMEType
Checks if the specified MIME type matches the FileFormat's default MIME type. The MIME types are compared ignoring upper/lower-case differences.- Parameters:
mimeType
- The MIME type to compare to the FileFormat's default MIME type.- Returns:
- true if the specified MIME type matches the FileFormat's default MIME type.
-
getMIMETypes
Gets the file format's MIME types.- Returns:
- An unmodifiable list of MIME type strings, e.g. "text/plain".
-
hasMIMEType
Checks if specified MIME type matches one of the FileFormat's MIME types. The MIME types are compared ignoring upper/lower-case differences.- Parameters:
mimeType
- The MIME type to compare to the FileFormat's MIME types.- Returns:
- true if the specified MIME type matches one of the FileFormat's MIME types.
-
getDefaultFileExtension
Gets the default file name extension for this file format.- Returns:
- A file name extension (excluding the dot), e.g. "txt", or null if there is no common file extension for the format.
-
hasDefaultFileExtension
Checks if the specified file name extension matches the FileFormat's default file name extension. The file name extension MIME types are compared ignoring upper/lower-case differences.- Parameters:
extension
- The file extension to compare to the FileFormat's file extension.- Returns:
- true if the file format has a default file name extension and if it matches the specified extension, false otherwise.
-
getFileExtensions
Gets the file format's file extensions.- Returns:
- An unmodifiable list of file extension strings, e.g. "txt".
-
hasFileExtension
Checks if the FileFormat's file extension is equal to the specified file extension. The file extensions are compared ignoring upper/lower-case differences.- Parameters:
extension
- The file extension to compare to the FileFormat's file extension.- Returns:
- true if the specified file extension is equal to the FileFormat's file extension.
-
getCharset
Get the (default) charset for this file format.- Returns:
- the (default) charset for this file format, or null if this format does not have a default charset.
-
hasCharset
public boolean hasCharset()Checks if the FileFormat has a (default) charset.- Returns:
- true if the FileFormat has a (default) charset.
-
equals
Compares FileFormat objects based on theirname
, ignoring case. -
hashCode
public int hashCode() -
toString
-
matchMIMEType
public static <FF extends FileFormat> Optional<FF> matchMIMEType(String mimeType, Iterable<FF> fileFormats) Tries to match the specified MIME type with the MIME types of the supplied file formats.- Parameters:
mimeType
- A MIME type, e.g. "text/plain".fileFormats
- The file formats to match the MIME type against.- Returns:
- A FileFormat object if the MIME type was recognized, or
Optional.empty()
otherwise.
-
matchFileName
public static <FF extends FileFormat> Optional<FF> matchFileName(String fileName, Iterable<FF> fileFormats) Tries to match the specified file name with the file extensions of the supplied file formats.- Parameters:
fileName
- A file name.fileFormats
- The file formats to match the file name extension against.- Returns:
- A FileFormat that matches the file name extension, or
Optional.empty()
otherwise.
-