Skip to content

Commit 93a4391

Browse files
committed
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #439
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/branches/2.0@1932975 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6450fe0 commit 93a4391

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

pdfbox/src/main/java/org/apache/pdfbox/util/filetypedetector/FileTypeDetector.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ public final class FileTypeDetector
4343

4444
// https://en.wikipedia.org/wiki/List_of_file_signatures
4545

46+
byte[] iiBytes = "II".getBytes(Charsets.ISO_8859_1);
47+
byte[] mmBytes = "MM".getBytes(Charsets.ISO_8859_1);
4648
root.addPath(FileType.JPEG, new byte[]{(byte)0xff, (byte)0xd8});
47-
root.addPath(FileType.TIFF, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00});
48-
root.addPath(FileType.TIFF, "MM".getBytes(Charsets.ISO_8859_1), new byte[]{0x00, 0x2a});
49+
root.addPath(FileType.TIFF, iiBytes, new byte[]{0x2a, 0x00});
50+
root.addPath(FileType.TIFF, mmBytes, new byte[]{0x00, 0x2a});
4951
root.addPath(FileType.PSD, "8BPS".getBytes(Charsets.ISO_8859_1));
5052
root.addPath(FileType.PNG, new byte[]{(byte)0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52});
5153
// TODO technically there are other very rare magic numbers for OS/2 BMP files...
@@ -62,13 +64,13 @@ public final class FileTypeDetector
6264

6365
// https://github.com/drewnoakes/metadata-extractor/issues/217
6466
//root.addPath(FileType.ARW, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x08, 0x00})
65-
root.addPath(FileType.CRW, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x1a, 0x00, 0x00, 0x00}, "HEAPCCDR".getBytes(Charsets.ISO_8859_1));
66-
root.addPath(FileType.CR2, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52});
67-
root.addPath(FileType.NEF, "MM".getBytes(Charsets.ISO_8859_1), new byte[]{0x00, 0x2a, 0x00, 0x00, 0x00, (byte)0x80, 0x00});
67+
root.addPath(FileType.CRW, iiBytes, new byte[]{0x1a, 0x00, 0x00, 0x00}, "HEAPCCDR".getBytes(Charsets.ISO_8859_1));
68+
root.addPath(FileType.CR2, iiBytes, new byte[]{0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x43, 0x52});
69+
root.addPath(FileType.NEF, mmBytes, new byte[]{0x00, 0x2a, 0x00, 0x00, 0x00, (byte)0x80, 0x00});
6870
root.addPath(FileType.ORF, "IIRO".getBytes(Charsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
6971
root.addPath(FileType.ORF, "IIRS".getBytes(Charsets.ISO_8859_1), new byte[]{(byte)0x08, 0x00});
7072
root.addPath(FileType.RAF, "FUJIFILMCCD-RAW".getBytes(Charsets.ISO_8859_1));
71-
root.addPath(FileType.RW2, "II".getBytes(Charsets.ISO_8859_1), new byte[]{0x55, 0x00});
73+
root.addPath(FileType.RW2, iiBytes, new byte[]{0x55, 0x00});
7274
}
7375

7476
private FileTypeDetector()

0 commit comments

Comments
 (0)