java.lang.Object
org.bzdev.util.SharedMimeInfo
- All Implemented Interfaces:
Closeable
,AutoCloseable
Utility class for generating a freedesktop.org shared-mime-info file.
These files are used to specify how the media type (MIME type) of a
file can be determined. The BZDev class library provides support for
file formats that are stylized ZIP files or stylized Java property
files, both with the media type encoded in the files. This class
provides an easy way to generate shared-mime-info entries.
The constructors determine the output stream. After a series of 'add'
methods, the method close()
must be called
(either directly or via a Java try-with-resources statement) once all
the entries have been added.
It is easy use the ESP scripting language. The following program is a good example:
When run with no arguments, this script will print a shared-mime-info file to standard output. To redirect it to a file, add the#!/usr/bin/scrunner -sEUN:true import org.bzdev.util.SharedMimeInfo; new SharedMimeInfo(global.getWriter()) .addConfigPropertyType(90, "application/foo", "foo", "foo type") .addZipDocType(80, "application/bar+zip", "bar", "bar type") .close();
scrunner
argument -o FILE
when the
script is run: if the script is named createMime, then one can run
the command
./createMime -o MimeInfo.xml
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor to write to standard output.SharedMimeInfo
(File file) Constructor given a file.SharedMimeInfo
(Writer writer) Constructor given a writer. -
Method Summary
Modifier and TypeMethodDescriptionaddConfigPropertyType
(int priority, String mediaType, String suffix, String comment) Add an entry to a share-mime-info file for a media type readable byConfigPropertyEditor
.addZipDocType
(int priority, String mediaType, String suffix, String comment) Add an entry to a share-mime-info file for a media type readable byZipDocFile
.void
close()
Close thisSharedMimeInfo
.
-
Constructor Details
-
SharedMimeInfo
Constructor given a file.- Parameters:
file
- a file used for output- Throws:
IOException
- if an IO error occurred
-
SharedMimeInfo
Constructor to write to standard output.- Throws:
IOException
- if an IO error occurred
-
SharedMimeInfo
Constructor given a writer.- Parameters:
writer
- aWriter
used for output
-
-
Method Details
-
close
Close thisSharedMimeInfo
. If the constructor's argument was not a file, the file being written will be closed, but not otherwise. In all cases, the output will be flushed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
addConfigPropertyType
public SharedMimeInfo addConfigPropertyType(int priority, String mediaType, String suffix, String comment) throws IOException, IllegalArgumentException Add an entry to a share-mime-info file for a media type readable byConfigPropertyEditor
.- Parameters:
priority
- the priority as an integer in the range [0,100]mediaType
- the media type (MIME type)suffix
- the file-name suffix for this type (null if there isn't one)comment
- a comment describing the media type; null if there is none- Returns:
- this object
- Throws:
IllegalArgumentException
- for an illegal argumentIOException
- if an IO error occurs
-
addZipDocType
public SharedMimeInfo addZipDocType(int priority, String mediaType, String suffix, String comment) throws IOException, IllegalArgumentException Add an entry to a share-mime-info file for a media type readable byZipDocFile
.This format is a stylized ZIP format, so the media type should end with the string "+zip".
- Parameters:
priority
- the priority as an integer in the range [0,100]mediaType
- the media type (MIME type)suffix
- the file-name suffix for this type (null if there isn't one)comment
- a comment describing the media type; null if there is none- Returns:
- this object
- Throws:
IllegalArgumentException
- for an illegal argumentIOException
- if an IO error occurs
-