public class Magic extends Object
| Modifier and Type | Field and Description |
|---|---|
static Magic |
BOM_UTF_16_BE |
static Magic |
BOM_UTF_16_LE |
static Magic |
BOM_UTF_32_BE
A couple of BOM magics
|
static Magic |
BOM_UTF_32_LE |
static Magic |
BOM_UTF_8 |
static Magic |
GZIP
First 2 bytes of a GZIP file have this signature.
|
static Magic |
NONE |
static Magic |
ZIP
First 4 bytes of a ZIP file have this signature.
|
| Modifier and Type | Method and Description |
|---|---|
static Magic |
define(String description,
Charset impliesEncoding,
int... bytesAsIntsForConvenience)
Defines a magic signature which can later be detected in
of(File) and of(byte[]). |
Charset |
encoding() |
boolean |
impliesEncoding() |
int |
length() |
static int |
longest() |
boolean |
matches(byte[] candidateBytes)
Tests whether or not a set of magic bytes matches this
Magic signature. |
static Magic |
of(byte[] bytes)
Matches the magic bytes with all defined and returns a match or
NONE. |
static Magic |
of(File file)
Extracts and matches the magic of the header in the given
file. |
String |
toString() |
public static final Magic NONE
public static final Magic ZIP
public static final Magic GZIP
public static final Magic BOM_UTF_32_BE
public static final Magic BOM_UTF_32_LE
public static final Magic BOM_UTF_16_BE
public static final Magic BOM_UTF_16_LE
public static final Magic BOM_UTF_8
public static Magic define(String description, Charset impliesEncoding, int... bytesAsIntsForConvenience)
of(File) and of(byte[]).description - description of the magic, typically which file it is.impliesEncoding - if a match for this to-be-defined magic implies that the contents in
this file has a certain encoding. Typically used for byte-order-mark.bytesAsIntsForConvenience - bytes that makes up the magic signature. Here specified as
an int[] for convenience of specifying those.Magic instance.public static Magic of(File file) throws IOException
file. If no magic matches
then NONE is returned.file - File to extract the magic from.Magic, or NONE if no match.IOException - for errors reading from the file.public static Magic of(byte[] bytes)
NONE.public static int longest()
public boolean matches(byte[] candidateBytes)
Magic signature.candidateBytes - magic bytes to test.true if the candidate bytes matches this signature, otherwise false.public int length()
public boolean impliesEncoding()
Magic implies the contents of the file being
of a certain encoding. If true then encoding() may be called to get the implied encoding.public Charset encoding()
impliesEncoding() is true,
otherwise throws IllegalStateException.Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.