/**
* Creates instances of MimeTypes.
*/
public class MimeTypesFactory {
/**
* Creates an empty instance; same as calling new MimeTypes().
*
* @return an empty instance
*/
public static MimeTypes create() {
return new MimeTypes();
}
/**
* Creates and returns a MimeTypes instance from the specified document.
* @throws MimeTypeException if the type configuration is invalid
*/
public static MimeTypes create(Document document) throws MimeTypeException {
MimeTypes mimeTypes = new MimeTypes();
new MimeTypesReader(mimeTypes).read(document);
mimeTypes.init();
return mimeTypes;
}
/**
* Creates and returns a MimeTypes instance from the specified input stream.
* Does not close the input stream(s).
* @throws IOException if the stream can not be read
* @throws MimeTypeException if the type configuration is invalid
*/
public static MimeTypes create(InputStream... inputStreams)
throws IOException, MimeTypeException {
MimeTypes mimeTypes = new MimeTypes();
MimeTypesReader reader = new MimeTypesReader(mimeTypes);
for(InputStream inputStream : inputStreams) {
reader.read(inputStream);
}
mimeTypes.init();
return mimeTypes;
}
/** @see #create(InputStream...) */
public static MimeTypes create(InputStream stream)
throws IOException, MimeTypeException {
return create(new InputStream[] { stream });
}
/**
* Creates and returns a MimeTypes instance from the resource
* at the location specified by the URL. Opens and closes the
* InputStream from the URL.
* If multiple URLs are supplied, then they are loaded in turn.
*
* @throws IOException if the URL can not be accessed
* @throws MimeTypeException if the type configuration is invalid
*/
public static MimeTypes create(URL... urls)
throws IOException, MimeTypeException {
InputStream[] streams = new InputStream[urls.length];
for(int i=0; i