This commit is contained in:
Looly 2023-03-30 02:35:12 +08:00
parent e7aa83220c
commit c9024ba8f9
2 changed files with 466 additions and 469 deletions

View File

@ -3155,7 +3155,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final boolean[] array, final boolean[] prefix) { public static boolean startWith(final boolean[] array, final boolean... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3186,7 +3186,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final byte[] array, final byte[] prefix) { public static boolean startWith(final byte[] array, final byte... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3212,7 +3212,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final char[] array, final char[] prefix) { public static boolean startWith(final char[] array, final char... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3243,7 +3243,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final double[] array, final double[] prefix) { public static boolean startWith(final double[] array, final double... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3274,7 +3274,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final float[] array, final float[] prefix) { public static boolean startWith(final float[] array, final float... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3305,7 +3305,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final int[] array, final int[] prefix) { public static boolean startWith(final int[] array, final int... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3336,7 +3336,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final long[] array, final long[] prefix) { public static boolean startWith(final long[] array, final long... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3367,7 +3367,7 @@ public class PrimitiveArrayUtil {
* @param prefix 前缀 * @param prefix 前缀
* @return 是否开头 * @return 是否开头
*/ */
public static boolean startWith(final short[] array, final short[] prefix) { public static boolean startWith(final short[] array, final short... prefix) {
if (array == prefix) { if (array == prefix) {
return true; return true;
} }
@ -3402,7 +3402,7 @@ public class PrimitiveArrayUtil {
* @param subArray 子数组 * @param subArray 子数组
* @return 是否局部匹配 * @return 是否局部匹配
*/ */
public static boolean isSubEquals(final byte[] array, final int offset, final byte[] subArray) { public static boolean isSubEquals(final byte[] array, final int offset, final byte... subArray) {
if (array == subArray) { if (array == subArray) {
return true; return true;
} }

View File

@ -38,6 +38,9 @@ public enum FileMagicNumber {
// region ----- image // region ----- image
/** /**
* jpeg * jpeg
* <pre>
* prefixFFD8FF
* </pre>
*/ */
JPEG("image/jpeg", "jpg") { JPEG("image/jpeg", "jpg") {
@Override @Override
@ -50,6 +53,9 @@ public enum FileMagicNumber {
}, },
/** /**
* jxr * jxr
* <pre>
* prefix4949BC
* </pre>
*/ */
JXR("image/vnd.ms-photo", "jxr") { JXR("image/vnd.ms-photo", "jxr") {
@Override @Override
@ -63,19 +69,17 @@ public enum FileMagicNumber {
}, },
/** /**
* apng * apng
* <pre>
* prefix 8位89504E47 0D0A1A0A
* </pre>
*/ */
APNG("image/apng", "apng") { APNG("image/apng", "apng") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
final boolean b = bytes.length > 8 final boolean b = ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x89) (byte) 0x89, (byte) 0x50, (byte) 0x4e, (byte) 0x47,
&& Objects.equals(bytes[1], (byte) 0x50) (byte) 0x0d, (byte) 0x0a, (byte) 0x1a, (byte) 0x0a
&& Objects.equals(bytes[2], (byte) 0x4e) );
&& Objects.equals(bytes[3], (byte) 0x47)
&& Objects.equals(bytes[4], (byte) 0x0d)
&& Objects.equals(bytes[5], (byte) 0x0a)
&& Objects.equals(bytes[6], (byte) 0x1a)
&& Objects.equals(bytes[7], (byte) 0x0a);
if (b) { if (b) {
int i = 8; int i = 8;
@ -101,130 +105,132 @@ public enum FileMagicNumber {
}, },
/** /**
* png * png
* <pre>
* prefix: 89504E47
* </pre>
*/ */
PNG("image/png", "png") { PNG("image/png", "png") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x89) (byte) 0x89, (byte) 0x50, (byte) 0x4e, (byte) 0x47
&& Objects.equals(bytes[1], (byte) 0x50) );
&& Objects.equals(bytes[2], (byte) 0x4e)
&& Objects.equals(bytes[3], (byte) 0x47);
} }
}, },
/** /**
* gif * gif
* <pre>
* prefix: 474946
* </pre>
*/ */
GIF("image/gif", "gif") { GIF("image/gif", "gif") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 2 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x47) (byte) 0x47, (byte) 0x49, (byte) 0x46
&& Objects.equals(bytes[1], (byte) 0x49) );
&& Objects.equals(bytes[2], (byte) 0x46);
} }
}, },
/** /**
* bmp * bmp
* <pre>
* prefix: 424D
* </pre>
*/ */
BMP("image/bmp", "bmp") { BMP("image/bmp", "bmp") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 1 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x42) (byte) 0x42, (byte) 0x4d
&& Objects.equals(bytes[1], (byte) 0x4d); );
} }
}, },
/** /**
* tiff * tiff
* <pre>
* prefix: 49492A00 or 4D4D002A
* </pre>
*/ */
TIFF("image/tiff", "tiff") { TIFF("image/tiff", "tiff") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
if (bytes.length < 4) { return ArrayUtil.startWith(bytes,
return false; (byte) 0x49, (byte) 0x49, (byte) 0x2a, (byte) 0x00
} ) || ArrayUtil.startWith(bytes,
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x49) (byte) 0x4d, (byte) 0x4d, (byte) 0x00, (byte) 0x2a
&& Objects.equals(bytes[1], (byte) 0x49) );
&& Objects.equals(bytes[2], (byte) 0x2a)
&& Objects.equals(bytes[3], (byte) 0x00);
final boolean flag2 = (Objects.equals(bytes[0], (byte) 0x4d)
&& Objects.equals(bytes[1], (byte) 0x4d)
&& Objects.equals(bytes[2], (byte) 0x00)
&& Objects.equals(bytes[3], (byte) 0x2a));
return flag1 || flag2;
} }
}, },
/** /**
* dwg * dwg
* <pre>
* prefix: 41433130
* </pre>
*/ */
DWG("image/vnd.dwg", "dwg") { DWG("image/vnd.dwg", "dwg") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 10 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x41) (byte) 0x41, (byte) 0x43, (byte) 0x31, (byte) 0x30
&& Objects.equals(bytes[1], (byte) 0x43) );
&& Objects.equals(bytes[2], (byte) 0x31)
&& Objects.equals(bytes[3], (byte) 0x30);
} }
}, },
/** /**
* webp * webp
* <pre>
* [8:11]: 57454250
* </pre>
*/ */
WEBP("image/webp", "webp") { WEBP("image/webp", "webp") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 11 return ArrayUtil.isSubEquals(bytes, 8,
&& Objects.equals(bytes[8], (byte) 0x57) (byte) 0x57, (byte) 0x45, (byte) 0x42, (byte) 0x50
&& Objects.equals(bytes[9], (byte) 0x45) );
&& Objects.equals(bytes[10], (byte) 0x42)
&& Objects.equals(bytes[11], (byte) 0x50);
} }
}, },
/** /**
* psd * psd
* <pre>
* prefix: 38425053
* </pre>
*/ */
PSD("image/vnd.adobe.photoshop", "psd") { PSD("image/vnd.adobe.photoshop", "psd") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x38) (byte) 0x38, (byte) 0x42, (byte) 0x50, (byte) 0x53
&& Objects.equals(bytes[1], (byte) 0x42) );
&& Objects.equals(bytes[2], (byte) 0x50)
&& Objects.equals(bytes[3], (byte) 0x53);
} }
}, },
/** /**
* icon * icon
* <pre>
* prefix: 00000100
* </pre>
*/ */
ICO("image/x-icon", "ico") { ICO("image/x-icon", "ico") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x00) (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00
&& Objects.equals(bytes[1], (byte) 0x00) );
&& Objects.equals(bytes[2], (byte) 0x01)
&& Objects.equals(bytes[3], (byte) 0x00);
} }
}, },
/** /**
* xcf * xcf
* <pre>
* prefix: 67696D70 20786366 2076
* </pre>
*/ */
XCF("image/x-xcf", "xcf") { XCF("image/x-xcf", "xcf") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 9 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x67) (byte) 0x67, (byte) 0x69, (byte) 0x6d, (byte) 0x70,
&& Objects.equals(bytes[1], (byte) 0x69) (byte) 0x20, (byte) 0x78, (byte) 0x63, (byte) 0x66,
&& Objects.equals(bytes[2], (byte) 0x6d) (byte) 0x20, (byte) 0x76
&& Objects.equals(bytes[3], (byte) 0x70) );
&& Objects.equals(bytes[4], (byte) 0x20)
&& Objects.equals(bytes[5], (byte) 0x78)
&& Objects.equals(bytes[6], (byte) 0x63)
&& Objects.equals(bytes[7], (byte) 0x66)
&& Objects.equals(bytes[8], (byte) 0x20)
&& Objects.equals(bytes[9], (byte) 0x76);
} }
}, },
// endregion // endregion
@ -232,61 +238,67 @@ public enum FileMagicNumber {
// region ----- audio // region ----- audio
/** /**
* wav * wav
* <pre>
* prefix: 52494646
* [8:11]: 57415645
* </pre>
*/ */
WAV("audio/x-wav", "wav") { WAV("audio/x-wav", "wav") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 11 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x52) (byte) 0x52, (byte) 0x49, (byte) 0x46, (byte) 0x46
&& Objects.equals(bytes[1], (byte) 0x49) ) && ArrayUtil.isSubEquals(bytes, 8,
&& Objects.equals(bytes[2], (byte) 0x46) (byte) 0x57, (byte) 0x41, (byte) 0x56, (byte) 0x45
&& Objects.equals(bytes[3], (byte) 0x46) );
&& Objects.equals(bytes[8], (byte) 0x57)
&& Objects.equals(bytes[9], (byte) 0x41)
&& Objects.equals(bytes[10], (byte) 0x56)
&& Objects.equals(bytes[11], (byte) 0x45);
} }
}, },
/** /**
* midi * midi
* <pre>
* prefix: 4D546864
* </pre>
*/ */
MIDI("audio/midi", "midi") { MIDI("audio/midi", "midi") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x4d) (byte) 0x4d, (byte) 0x54, (byte) 0x68, (byte) 0x64
&& Objects.equals(bytes[1], (byte) 0x54) );
&& Objects.equals(bytes[2], (byte) 0x68)
&& Objects.equals(bytes[3], (byte) 0x64);
} }
}, },
/** /**
* mpeg-mp3 * mpeg-mp3
* <pre>
* prefix: 494433 or FFFB or FFF3 or FFF2
* </pre>
*/ */
MP3("audio/mpeg", "mp3") { MP3("audio/mpeg", "mp3") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
if (bytes.length < 2) { return ArrayUtil.startWith(bytes,
return false; (byte) 0x49, (byte) 0x44, (byte) 0x33
} ) || ArrayUtil.startWith(bytes,
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x49) && Objects.equals(bytes[1], (byte) 0x44) && Objects.equals(bytes[2], (byte) 0x33); (byte) 0xFF, (byte) 0xFB
final boolean flag2 = Objects.equals(bytes[0], (byte) 0xFF) && Objects.equals(bytes[1], (byte) 0xFB); ) || ArrayUtil.startWith(bytes,
final boolean flag3 = Objects.equals(bytes[0], (byte) 0xFF) && Objects.equals(bytes[1], (byte) 0xF3); (byte) 0xFF, (byte) 0xF3
final boolean flag4 = Objects.equals(bytes[0], (byte) 0xFF) && Objects.equals(bytes[1], (byte) 0xF2); ) || ArrayUtil.startWith(bytes,
return flag1 || flag2 || flag3 || flag4; (byte) 0xFF, (byte) 0xF2
);
} }
}, },
/** /**
* ogg * ogg
* <pre>
* prefix: 4F676753
* </pre>
*/ */
OGG("audio/ogg", "ogg") { OGG("audio/ogg", "ogg") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x4f) (byte) 0x4F, (byte) 0x67, (byte) 0x67, (byte) 0x53
&& Objects.equals(bytes[1], (byte) 0x67) );
&& Objects.equals(bytes[2], (byte) 0x67)
&& Objects.equals(bytes[3], (byte) 0x53);
} }
}, },
/** /**
@ -295,11 +307,9 @@ public enum FileMagicNumber {
FLAC("audio/x-flac", "flac") { FLAC("audio/x-flac", "flac") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 3 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x66) (byte) 0x66, (byte) 0x4c, (byte) 0x61, (byte) 0x43
&& Objects.equals(bytes[1], (byte) 0x4c) );
&& Objects.equals(bytes[2], (byte) 0x61)
&& Objects.equals(bytes[3], (byte) 0x43);
} }
}, },
/** /**
@ -342,30 +352,14 @@ public enum FileMagicNumber {
AMR("audio/amr", "amr") { AMR("audio/amr", "amr") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
//single-channel return ArrayUtil.startWith(bytes,
if (bytes.length < 11) { (byte) 0x23, (byte) 0x21, (byte) 0x41, (byte) 0x4d,
return false; (byte) 0x52, (byte) 0x0A
} ) || ArrayUtil.startWith(bytes,
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x23) (byte) 0x23, (byte) 0x21, (byte) 0x41, (byte) 0x4d,
&& Objects.equals(bytes[1], (byte) 0x21) (byte) 0x52, (byte) 0x5F, (byte) 0x4d, (byte) 0x43,
&& Objects.equals(bytes[2], (byte) 0x41) (byte) 0x31, (byte) 0x2e, (byte) 0x30, (byte) 0x0a
&& Objects.equals(bytes[3], (byte) 0x4d) );
&& Objects.equals(bytes[4], (byte) 0x52)
&& Objects.equals(bytes[5], (byte) 0x0A);
//multi-channel:
final boolean flag2 = Objects.equals(bytes[0], (byte) 0x23)
&& Objects.equals(bytes[1], (byte) 0x21)
&& Objects.equals(bytes[2], (byte) 0x41)
&& Objects.equals(bytes[3], (byte) 0x4d)
&& Objects.equals(bytes[4], (byte) 0x52)
&& Objects.equals(bytes[5], (byte) 0x5F)
&& Objects.equals(bytes[6], (byte) 0x4d)
&& Objects.equals(bytes[7], (byte) 0x43)
&& Objects.equals(bytes[8], (byte) 0x31)
&& Objects.equals(bytes[9], (byte) 0x2e)
&& Objects.equals(bytes[10], (byte) 0x30)
&& Objects.equals(bytes[11], (byte) 0x0a);
return flag1 || flag2;
} }
}, },
/** /**
@ -374,9 +368,9 @@ public enum FileMagicNumber {
AC3("audio/ac3", "ac3") { AC3("audio/ac3", "ac3") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 2 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x0b) (byte) 0x0b, (byte) 0x77
&& Objects.equals(bytes[1], (byte) 0x77); );
} }
}, },
/** /**
@ -390,6 +384,7 @@ public enum FileMagicNumber {
&& Objects.equals(bytes[1], (byte) 0x4f) && Objects.equals(bytes[1], (byte) 0x4f)
&& Objects.equals(bytes[2], (byte) 0x52) && Objects.equals(bytes[2], (byte) 0x52)
&& Objects.equals(bytes[3], (byte) 0x4d) && Objects.equals(bytes[3], (byte) 0x4d)
&& Objects.equals(bytes[8], (byte) 0x41) && Objects.equals(bytes[8], (byte) 0x41)
&& Objects.equals(bytes[9], (byte) 0x49) && Objects.equals(bytes[9], (byte) 0x49)
&& Objects.equals(bytes[10], (byte) 0x46) && Objects.equals(bytes[10], (byte) 0x46)
@ -406,22 +401,26 @@ public enum FileMagicNumber {
WOFF("font/woff", "woff") { WOFF("font/woff", "woff") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
if(bytes.length < 8){ if (bytes.length < 8) {
return false; return false;
} }
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77) final boolean flag1 =
Objects.equals(bytes[0], (byte) 0x77)
&& Objects.equals(bytes[1], (byte) 0x4f) && Objects.equals(bytes[1], (byte) 0x4f)
&& Objects.equals(bytes[2], (byte) 0x46) && Objects.equals(bytes[2], (byte) 0x46)
&& Objects.equals(bytes[3], (byte) 0x46); && Objects.equals(bytes[3], (byte) 0x46);
final boolean flag2 = Objects.equals(bytes[4], (byte) 0x00) final boolean flag2 =
Objects.equals(bytes[4], (byte) 0x00)
&& Objects.equals(bytes[5], (byte) 0x01) && Objects.equals(bytes[5], (byte) 0x01)
&& Objects.equals(bytes[6], (byte) 0x00) && Objects.equals(bytes[6], (byte) 0x00)
&& Objects.equals(bytes[7], (byte) 0x00); && Objects.equals(bytes[7], (byte) 0x00);
final boolean flag3 = Objects.equals(bytes[4], (byte) 0x4f) final boolean flag3 =
Objects.equals(bytes[4], (byte) 0x4f)
&& Objects.equals(bytes[5], (byte) 0x54) && Objects.equals(bytes[5], (byte) 0x54)
&& Objects.equals(bytes[6], (byte) 0x54) && Objects.equals(bytes[6], (byte) 0x54)
&& Objects.equals(bytes[7], (byte) 0x4f); && Objects.equals(bytes[7], (byte) 0x4f);
final boolean flag4 = Objects.equals(bytes[4], (byte) 0x74) final boolean flag4 =
Objects.equals(bytes[4], (byte) 0x74)
&& Objects.equals(bytes[5], (byte) 0x72) && Objects.equals(bytes[5], (byte) 0x72)
&& Objects.equals(bytes[6], (byte) 0x75) && Objects.equals(bytes[6], (byte) 0x75)
&& Objects.equals(bytes[7], (byte) 0x65); && Objects.equals(bytes[7], (byte) 0x65);
@ -434,22 +433,26 @@ public enum FileMagicNumber {
WOFF2("font/woff2", "woff2") { WOFF2("font/woff2", "woff2") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
if(bytes.length < 8){ if (bytes.length < 8) {
return false; return false;
} }
final boolean flag1 = Objects.equals(bytes[0], (byte) 0x77) final boolean flag1 =
Objects.equals(bytes[0], (byte) 0x77)
&& Objects.equals(bytes[1], (byte) 0x4f) && Objects.equals(bytes[1], (byte) 0x4f)
&& Objects.equals(bytes[2], (byte) 0x46) && Objects.equals(bytes[2], (byte) 0x46)
&& Objects.equals(bytes[3], (byte) 0x32); && Objects.equals(bytes[3], (byte) 0x32);
final boolean flag2 = Objects.equals(bytes[4], (byte) 0x00) final boolean flag2 =
Objects.equals(bytes[4], (byte) 0x00)
&& Objects.equals(bytes[5], (byte) 0x01) && Objects.equals(bytes[5], (byte) 0x01)
&& Objects.equals(bytes[6], (byte) 0x00) && Objects.equals(bytes[6], (byte) 0x00)
&& Objects.equals(bytes[7], (byte) 0x00); && Objects.equals(bytes[7], (byte) 0x00);
final boolean flag3 = Objects.equals(bytes[4], (byte) 0x4f) final boolean flag3 =
Objects.equals(bytes[4], (byte) 0x4f)
&& Objects.equals(bytes[5], (byte) 0x54) && Objects.equals(bytes[5], (byte) 0x54)
&& Objects.equals(bytes[6], (byte) 0x54) && Objects.equals(bytes[6], (byte) 0x54)
&& Objects.equals(bytes[7], (byte) 0x4f); && Objects.equals(bytes[7], (byte) 0x4f);
final boolean flag4 = Objects.equals(bytes[4], (byte) 0x74) final boolean flag4 =
Objects.equals(bytes[4], (byte) 0x74)
&& Objects.equals(bytes[5], (byte) 0x72) && Objects.equals(bytes[5], (byte) 0x72)
&& Objects.equals(bytes[6], (byte) 0x75) && Objects.equals(bytes[6], (byte) 0x75)
&& Objects.equals(bytes[7], (byte) 0x65); && Objects.equals(bytes[7], (byte) 0x65);
@ -1144,7 +1147,7 @@ public enum FileMagicNumber {
if (bytes.length > 515 && ArrayUtil.isSubEquals(bytes, 0, byte1)) { if (bytes.length > 515 && ArrayUtil.isSubEquals(bytes, 0, byte1)) {
final byte[] byte2 = new byte[]{(byte) 0xec, (byte) 0xa5, (byte) 0xc1, (byte) 0x00}; final byte[] byte2 = new byte[]{(byte) 0xec, (byte) 0xa5, (byte) 0xc1, (byte) 0x00};
// check 512:516 // check 512:516
if(ArrayUtil.isSubEquals(bytes, 512, byte2)){ if (ArrayUtil.isSubEquals(bytes, 512, byte2)) {
return true; return true;
} }
final byte[] byte3 = new byte[]{(byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4d, (byte) 0x53, (byte) 0x57, (byte) 0x6f, (byte) 0x72, (byte) 0x64 final byte[] byte3 = new byte[]{(byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x4d, (byte) 0x53, (byte) 0x57, (byte) 0x6f, (byte) 0x72, (byte) 0x64
@ -1241,15 +1244,9 @@ public enum FileMagicNumber {
WASM("application/wasm", "wasm") { WASM("application/wasm", "wasm") {
@Override @Override
public boolean match(final byte[] bytes) { public boolean match(final byte[] bytes) {
return bytes.length > 7 return ArrayUtil.startWith(bytes,
&& Objects.equals(bytes[0], (byte) 0x00) (byte) 0x00, (byte) 0x61, (byte) 0x73, (byte) 0x6D, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00
&& Objects.equals(bytes[1], (byte) 0x61) );
&& Objects.equals(bytes[2], (byte) 0x73)
&& Objects.equals(bytes[3], (byte) 0x6D)
&& Objects.equals(bytes[4], (byte) 0x01)
&& Objects.equals(bytes[5], (byte) 0x00)
&& Objects.equals(bytes[6], (byte) 0x00)
&& Objects.equals(bytes[7], (byte) 0x00);
} }
}, },
/** /**