Package org.apache.poi.poifs.filesystem
Enum FileMagic
- java.lang.Object
-
- java.lang.Enum<FileMagic>
-
- org.apache.poi.poifs.filesystem.FileMagic
-
- All Implemented Interfaces:
Serializable
,Comparable<FileMagic>
public enum FileMagic extends Enum<FileMagic>
The file magic number, i.e. the file identification based on the first bytes of the file
-
-
Enum Constant Summary
Enum Constants Enum Constant Description BIFF2
BIFF2 raw stream - for Excel 2BIFF3
BIFF3 raw stream - for Excel 3BIFF4
BIFF4 raw stream - for Excel 4BMP
BMP imageEMF
EMF imageGIF
GIF imageHTML
Some different HTML documentsJPEG
JPEG imageMSWRITE
Old MS Write raw streamOLE2
OLE2 / BIFF8+ stream used for Office 97 and higher documentsOOXML
OOXML / ZIP stream - The first 4 bytes of an OOXML file, used in detectionPDF
PDF documentPNG
PNG ImageRTF
RTF documentTIFF
TIFF ImageUNKNOWN
UNKNOWN magicWMF
WMF image with a placeable headerWORD2
XML
XML file - The first 5 bytes of a raw XML file, used in detection
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InputStream
prepareToCheckMagic(InputStream stream)
Checks if anInputStream
can be reset (i.e.static FileMagic
valueOf(byte[] magic)
Returns the enum constant of this type with the specified name.static FileMagic
valueOf(File inp)
Get the file magic of the suppliedFile
static FileMagic
valueOf(InputStream inp)
Get the file magic of the supplied InputStream (which MUST support mark and reset).static FileMagic
valueOf(String name)
Returns the enum constant of this type with the specified name.static FileMagic[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
OLE2
public static final FileMagic OLE2
OLE2 / BIFF8+ stream used for Office 97 and higher documents
-
OOXML
public static final FileMagic OOXML
OOXML / ZIP stream - The first 4 bytes of an OOXML file, used in detection
-
XML
public static final FileMagic XML
XML file - The first 5 bytes of a raw XML file, used in detection
-
BIFF2
public static final FileMagic BIFF2
BIFF2 raw stream - for Excel 2
-
BIFF3
public static final FileMagic BIFF3
BIFF3 raw stream - for Excel 3
-
BIFF4
public static final FileMagic BIFF4
BIFF4 raw stream - for Excel 4
-
MSWRITE
public static final FileMagic MSWRITE
Old MS Write raw stream
-
RTF
public static final FileMagic RTF
RTF document
-
PDF
public static final FileMagic PDF
PDF document
-
HTML
public static final FileMagic HTML
Some different HTML documents
-
WORD2
public static final FileMagic WORD2
-
JPEG
public static final FileMagic JPEG
JPEG image
-
GIF
public static final FileMagic GIF
GIF image
-
PNG
public static final FileMagic PNG
PNG Image
-
TIFF
public static final FileMagic TIFF
TIFF Image
-
WMF
public static final FileMagic WMF
WMF image with a placeable header
-
EMF
public static final FileMagic EMF
EMF image
-
BMP
public static final FileMagic BMP
BMP image
-
UNKNOWN
public static final FileMagic UNKNOWN
UNKNOWN magic
-
-
Method Detail
-
values
public static FileMagic[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (FileMagic c : FileMagic.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static FileMagic valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
valueOf
public static FileMagic valueOf(byte[] magic)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
magic
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
valueOf
public static FileMagic valueOf(File inp) throws IOException
Get the file magic of the suppliedFile
Even if this method returns
UNKNOWN
it could potentially mean, that the ZIP stream has leading junk bytes- Parameters:
inp
- a file to be identified- Throws:
IOException
-
valueOf
public static FileMagic valueOf(InputStream inp) throws IOException
Get the file magic of the supplied InputStream (which MUST support mark and reset).If unsure if your InputStream does support mark / reset, use
prepareToCheckMagic(InputStream)
to wrap it and make sure to always use that, and not the original!Even if this method returns
UNKNOWN
it could potentially mean, that the ZIP stream has leading junk bytes- Parameters:
inp
- An InputStream which supports either mark/reset- Throws:
IOException
-
prepareToCheckMagic
public static InputStream prepareToCheckMagic(InputStream stream)
Checks if anInputStream
can be reset (i.e. used for checking the header magic) and wraps it if not- Parameters:
stream
- stream to be checked for wrapping- Returns:
- a mark enabled stream
-
-