FileTypeDetector
Stay organized with collections
Save and categorize content based on your preferences.
A file type detector for probing a file to guess its file type.
A file type detector is a concrete implementation of this class, has a
zero-argument constructor, and implements the abstract methods specified
below.
The means by which a file type detector determines the file type is
highly implementation specific. A simple implementation might examine the
file extension (a convention used in some platforms) and map it to
a file type. In other cases, the file type may be stored as a file attribute or the bytes in a
file may be examined to guess its file type.
Protected Constructor Summary
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Protected Constructors
protected
FileTypeDetector
()
Initializes a new instance of this class.
Public Methods
public
abstract
String
probeContentType
(Path path)
Probes the given file to guess its content type.
The means by which this method determines the file type is highly
implementation specific. It may simply examine the file name, it may use
a file attribute,
or it may examines bytes in the file.
The probe result is the string form of the value of a
Multipurpose Internet Mail Extension (MIME) content type as
defined by RFC 2045:
Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet
Message Bodies. The string must be parsable according to the
grammar in the RFC 2045.
Parameters
path |
the path to the file to probe |
Returns
- The content type or
null
if the file type is not
recognized
Throws
IOException |
An I/O error occurs |
SecurityException |
If the implementation requires to access the file, and a
security manager is installed, and it denies an unspecified
permission required by a file system provider implementation.
If the file reference is associated with the default file system
provider then the SecurityManager.checkRead(String) method
is invoked to check read access to the file. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["`FileTypeDetector` is an abstract class used to determine the type of a file by probing its content."],["Implementations of this class may use various methods to determine file type, such as examining file extensions, attributes, or file content."],["The `probeContentType` method returns the MIME content type of the file as a string or `null` if the type is not recognized."],["It is highly implementation-specific how a `FileTypeDetector` determines the file type."]]],["`FileTypeDetector` is an abstract class for guessing a file's type. Concrete implementations use a zero-argument constructor and determine file type by methods such as examining the file extension, attributes, or bytes. The `probeContentType(Path path)` method, which must be implemented, guesses the file's content type and returns a MIME string, or `null` if unrecognized. This probing method can throw an `IOException` or `SecurityException`. The file name is the only required input.\n"]]