Class MagicNumber
- java.lang.Object
-
- org.arakhne.afc.inputoutput.filetype.MagicNumber
-
- All Implemented Interfaces:
Comparable<MagicNumber>
- Direct Known Subclasses:
ByteMagicNumber
,JarMagicNumber
,XMLMagicNumber
,ZipArchiveMagicNumber
,ZipMagicNumber
public abstract class MagicNumber extends Object implements Comparable<MagicNumber>
This clas defines a set of informations that could distinguish a file content from another one. It is also known as Magic Number on several operating systems.- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:40
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- inputoutput
-
-
Constructor Summary
Constructors Constructor Description MagicNumber(javax.activation.MimeType mimeType, String formatVersion, javax.activation.MimeType... hostMimeTypes)
Constructor.MagicNumber(javax.activation.MimeType mimeType, javax.activation.MimeType... hostMimeTypes)
Constructor.MagicNumber(MimeName mimeType, String formatVersion, MimeName... hostMimeTypes)
Constructor.MagicNumber(MimeName mimeType, MimeName... hostMimeTypes)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(MagicNumber number)
protected void
doStreamEncoding(MagicNumberStream stream)
Invoked beforeisContentType(MagicNumberStream)
to prepare the stream.String
getFormatVersion()
Replies the format version for this magic number.(package private) javax.activation.MimeType[]
getHostMimeTypes()
Replies the MIME type used by the Java virtal machine for this magic number.javax.activation.MimeType
getMimeType()
Replies the MIME type for this magic number.protected abstract boolean
isContentType(MagicNumberStream stream)
Replies if the specified stream contains data that corresponds to this magic number.protected void
undoStreamEncoding(MagicNumberStream stream)
Invoked beforeisContentType(MagicNumberStream)
to unprepare the stream.
-
-
-
Constructor Detail
-
MagicNumber
public MagicNumber(javax.activation.MimeType mimeType, javax.activation.MimeType... hostMimeTypes)
Constructor.- Parameters:
mimeType
- is the MIME type associated to this magic number.hostMimeTypes
- are the MIME types given by the low-level analyzer and associated to this number.
-
MagicNumber
public MagicNumber(javax.activation.MimeType mimeType, String formatVersion, javax.activation.MimeType... hostMimeTypes)
Constructor.- Parameters:
mimeType
- is the MIME type associated to this magic number.formatVersion
- is a string representing the format version supported by this magic number.hostMimeTypes
- are the MIME types given by the low-level analyzer and associated to this number.
-
MagicNumber
public MagicNumber(MimeName mimeType, MimeName... hostMimeTypes)
Constructor.- Parameters:
mimeType
- is the MIME type associated to this magic number.hostMimeTypes
- are the MIME types given by the low-level analyzer and associated to this number.- Throws:
IllegalArgumentException
- if one of the MIME types cannot be parsed.
-
MagicNumber
public MagicNumber(MimeName mimeType, String formatVersion, MimeName... hostMimeTypes)
Constructor.- Parameters:
mimeType
- is the MIME type associated to this magic number.formatVersion
- is a string representing the format version supported by this magic number.hostMimeTypes
- are the MIME types given by the low-level analyzer and associated to this number.- Throws:
IllegalArgumentException
- if one of the MIME types cannot be parsed.
-
-
Method Detail
-
getHostMimeTypes
@Pure javax.activation.MimeType[] getHostMimeTypes()
Replies the MIME type used by the Java virtal machine for this magic number.- Returns:
- the low-level MIME type.
-
getMimeType
@Pure public javax.activation.MimeType getMimeType()
Replies the MIME type for this magic number.- Returns:
- the MIME type.
-
getFormatVersion
@Pure public String getFormatVersion()
Replies the format version for this magic number.- Returns:
- the format version or
null
.
-
doStreamEncoding
protected void doStreamEncoding(MagicNumberStream stream) throws IOException
Invoked beforeisContentType(MagicNumberStream)
to prepare the stream.- Parameters:
stream
- is the stream to analyse.- Throws:
IOException
- in case of IO error.
-
undoStreamEncoding
protected void undoStreamEncoding(MagicNumberStream stream) throws IOException
Invoked beforeisContentType(MagicNumberStream)
to unprepare the stream.- Parameters:
stream
- is the stream to analyse.- Throws:
IOException
- in case of IO error.
-
isContentType
@Pure protected abstract boolean isContentType(MagicNumberStream stream)
Replies if the specified stream contains data that corresponds to this magic number.- Parameters:
stream
- is the stream to analyse.- Returns:
true
if the stream is containing this magic number, otherwisefalse
-
compareTo
@Pure public int compareTo(MagicNumber number)
- Specified by:
compareTo
in interfaceComparable<MagicNumber>
-
-