Author: tilman
Date: Sat Apr 11 03:25:46 2026
New Revision: 1932975

Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #439

Modified:
   
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java

Modified: 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java
==============================================================================
--- 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java
      Sat Apr 11 01:29:35 2026        (r1932974)
+++ 
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java
      Sat Apr 11 03:25:46 2026        (r1932975)
@@ -43,9 +43,11 @@ public final class FileTypeDetector
 
         // https://en.wikipedia.org/wiki/List_of_file_signatures
 
+        byte[] iiBytes = "II".getBytes(Charsets.ISO_8859_1);
+        byte[] mmBytes = "MM".getBytes(Charsets.ISO_8859_1);
         root.addPath(FileType.JPEG, new byte[]{(byte)0xff, (byte)0xd8});
-        root.addPath(FileType.TIFF, "II".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x2a, 0x00});
-        root.addPath(FileType.TIFF, "MM".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x00, 0x2a});
+        root.addPath(FileType.TIFF, iiBytes, new byte[]{0x2a, 0x00});
+        root.addPath(FileType.TIFF, mmBytes, new byte[]{0x00, 0x2a});
         root.addPath(FileType.PSD, "8BPS".getBytes(Charsets.ISO_8859_1));
         root.addPath(FileType.PNG, new byte[]{(byte)0x89, 0x50, 0x4E, 0x47, 
0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52});
         // TODO technically there are other very rare magic numbers for OS/2 
BMP files...
@@ -62,13 +64,13 @@ public final class FileTypeDetector
 
         // https://github.com/drewnoakes/metadata-extractor/issues/217
         //root.addPath(FileType.ARW, "II".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x2a, 0x00, 0x08, 0x00})
-        root.addPath(FileType.CRW, "II".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x1a, 0x00, 0x00, 0x00}, "HEAPCCDR".getBytes(Charsets.ISO_8859_1));
-        root.addPath(FileType.CR2, "II".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52});
-        root.addPath(FileType.NEF, "MM".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x00, 0x2a, 0x00, 0x00, 0x00, (byte)0x80, 0x00});
+        root.addPath(FileType.CRW, iiBytes, new byte[]{0x1a, 0x00, 0x00, 
0x00}, "HEAPCCDR".getBytes(Charsets.ISO_8859_1));
+        root.addPath(FileType.CR2, iiBytes, new byte[]{0x2a, 0x00, 0x10, 0x00, 
0x00, 0x00, 0x43, 0x52});
+        root.addPath(FileType.NEF, mmBytes, new byte[]{0x00, 0x2a, 0x00, 0x00, 
0x00, (byte)0x80, 0x00});
         root.addPath(FileType.ORF, "IIRO".getBytes(Charsets.ISO_8859_1), new 
byte[]{(byte)0x08, 0x00});
         root.addPath(FileType.ORF, "IIRS".getBytes(Charsets.ISO_8859_1), new 
byte[]{(byte)0x08, 0x00});
         root.addPath(FileType.RAF, 
"FUJIFILMCCD-RAW".getBytes(Charsets.ISO_8859_1));
-        root.addPath(FileType.RW2, "II".getBytes(Charsets.ISO_8859_1), new 
byte[]{0x55, 0x00});
+        root.addPath(FileType.RW2, iiBytes, new byte[]{0x55, 0x00});
     }
 
     private FileTypeDetector()

Reply via email to