Skip to content

Commit d407eac

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

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
@@ -42,9 +42,11 @@ public final class FileTypeDetector
4242

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

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

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

7375
private FileTypeDetector()

0 commit comments

Comments
 (0)