Skip to content

Commit 411c0fe

Browse files
committed
refactor: use enhanced instanceof
1 parent 49461d9 commit 411c0fe

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/main/java/org/jadice/filetype/matchers/PDFMatcher.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ private void provideXMPMetadata(final Map<String, Object> pdfDetails, final PDMe
189189

190190
private static void extractFilesFromPage(final PDPage page, final List<String> filenames) throws IOException {
191191
for (PDAnnotation annotation : page.getAnnotations()) {
192-
if (annotation instanceof PDAnnotationFileAttachment) {
193-
PDAnnotationFileAttachment annotationFileAttachment = (PDAnnotationFileAttachment) annotation;
192+
if (annotation instanceof PDAnnotationFileAttachment annotationFileAttachment) {
194193
PDFileSpecification fileSpec = annotationFileAttachment.getFile();
195-
if (fileSpec instanceof PDComplexFileSpecification) {
196-
PDComplexFileSpecification complexFileSpec = (PDComplexFileSpecification) fileSpec;
194+
if (fileSpec instanceof PDComplexFileSpecification complexFileSpec) {
197195
PDEmbeddedFile embeddedFile = getEmbeddedFile(complexFileSpec);
198196
if (embeddedFile != null) {
199197
extractFile(filenames, complexFileSpec.getFilename());
@@ -291,11 +289,11 @@ private static void addTextInfo(final Map<String, Object> pdfDetails, final PDDo
291289
*/
292290
private static void checkIfXRechnung(final Map<String, Object> pdfDetails) {
293291
final Object metadata = pdfDetails.get(METADATA_KEY);
294-
if (metadata instanceof String) {
292+
if (metadata instanceof String metadataString) {
295293
try {
296294
final XMLMatcher xmlMatcher = new XMLMatcher();
297295
final Context xmlContext = new Context(
298-
new MemoryInputStream(((String) metadata).getBytes(StandardCharsets.UTF_8)),
296+
new MemoryInputStream(metadataString.getBytes(StandardCharsets.UTF_8)),
299297
new HashMap<>(), null, Locale.ENGLISH, "");
300298
final boolean isXRechnung = xmlMatcher.matches(xmlContext);
301299
if (isXRechnung) {

src/main/java/org/jadice/filetype/matchers/XMLMatcher.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ private boolean hasXmlProlog(final SeekableInputStream sis) throws IOException {
182182
* {@link ByteOrderMark BOM}
183183
*/
184184
private InputStreamReader createReader(final SeekableInputStream sis) throws IOException {
185-
final BOMInputStream bomIS = new BOMInputStream(sis, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE,
186-
ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
185+
final BOMInputStream bomIS = BOMInputStream.builder().setInputStream(sis)
186+
.setByteOrderMarks(ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE,
187+
ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE)
188+
.get();
187189

188190
final Charset charset;
189191
if (bomIS.hasBOM()) {
@@ -323,7 +325,7 @@ private static void trySetXercesSecurityManager(SAXParser parser) {
323325
//"com.sun.org.apache.xerces.internal.util.SecurityManager",
324326
XERCES_SECURITY_MANAGER}) {
325327
try {
326-
Object mgr = Class.forName(securityManagerClassName).newInstance();
328+
Object mgr = Class.forName(securityManagerClassName).getDeclaredConstructor().newInstance();
327329
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
328330
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
329331

0 commit comments

Comments
 (0)