@@ -36,10 +36,8 @@ public class ImageFileValidator implements ConstraintValidator<ImageFile, Multip
36
36
private static final Logger LOG = LoggerFactory .getLogger (ImageFileValidator .class );
37
37
38
38
// see https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure
39
- // CheckStyle: ignore NoWhitespaceAfterCheck for next 3 lines
40
- private static final byte [][] JPEG_SIGNATURES = {
41
- { (byte )0xFF , (byte )0xD8 , (byte )0xFF , (byte )0xE0 },
42
- { (byte )0xFF , (byte )0xD8 , (byte )0xFF , (byte )0xE1 }
39
+ private static final byte [] JPEG_SIGNATURE = {
40
+ (byte )0xFF , (byte )0xD8 , (byte )0xFF ,
43
41
};
44
42
45
43
// see https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
@@ -50,14 +48,8 @@ public class ImageFileValidator implements ConstraintValidator<ImageFile, Multip
50
48
private static boolean isJpeg (byte [] bytes ) {
51
49
// FIXME: also check that last 2 bytes are FF D9 (use RandomAccessFile)
52
50
// FIXME(java9): use Arrays.equals() with 6 parameters to avoid memory allocation
53
- byte [] firstBytes = Arrays .copyOf (bytes , JPEG_SIGNATURES [0 ].length );
54
- for (byte [] signature : JPEG_SIGNATURES ) {
55
- if (Arrays .equals (firstBytes , signature )) {
56
- return true ;
57
- }
58
- }
59
-
60
- return false ;
51
+ byte [] firstBytes = Arrays .copyOf (bytes , JPEG_SIGNATURE .length );
52
+ return Arrays .equals (firstBytes , JPEG_SIGNATURE );
61
53
}
62
54
63
55
private static boolean isPng (byte [] bytes ) {
0 commit comments