Mimes

trait Mimes

A utility to help with mime type detection for a given file path or url.

Companion:
object
class Object
trait Matchable
class Any
object MimeTypes.type

Value members

Concrete methods

def apply(input: InputStream): String
def apply(file: File): String
def apply(bytes: Array[Byte]): String
def apply(uri: URI): String
def bytesMime(content: Array[Byte], fallback: String): String

Detects the mime type of a given Byte array.

Detects the mime type of a given Byte array.

When inappropriate MIME Type can not be inferred, "text/pain" is returned.

Value parameters:
content

The Byte array for which to detect the mime type

fallback

A fallback value in case no mime type can be found

def fileMime(file: File, fallback: String): String

Detects the mime type of a given File.

Detects the mime type of a given File.

When inappropriate MIME Type can not be inferred, "application/octet-stream" is returned.

This method guesses the MIME type using java.net.URLConnection.guessContentTypeFromName. Therefore, by defining an arbitrary MIME type in the configuration file specified by the content.types.user.table property, an arbitrary MIME type can be guessed.

Value parameters:
fallback

A fallback value in case no mime type can be found

file

The File for which to detect the mime type

def inputStreamMime(input: InputStream, fallback: String): String

Detects the mime type of a given InputStream.

Detects the mime type of a given InputStream.

When inappropriate MIME Type can not be inferred, "application/octet-stream" is returned.

Value parameters:
fallback

A fallback value in case no mime type can be found

input

The InputStream for which to detect the mime type

def urlMime(url: String, fallback: String): String

Detects the mime type of a given url.

Detects the mime type of a given url.

When inappropriate MIME Type can not be inferred, "application/octet-stream" is returned.

This method guesses the MIME type using java.net.URLConnection.guessContentTypeFromName. Therefore, by defining an arbitrary MIME type in the configuration file specified by the content.types.user.table property, an arbitrary MIME type can be guessed.

Value parameters:
fallback

A fallback value in case no mime type can be found

url

The url for which to detect the mime type