This is an automated email from the ASF dual-hosted git repository.

tilman pushed a commit to branch branch_2x
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 184248f86c221a11b761b7296e8eddbd24cd6953
Author: Tilman Hausherr <til...@apache.org>
AuthorDate: Sat Aug 10 12:11:58 2024 +0200

    TIKA-4290: replace deprecated, fix javadoc, remove unneeded code
---
 .../apache/tika/parser/iwork/iwana/IWork13PackageParser.java   |  2 +-
 .../apache/tika/parser/iwork/iwana/IWork18PackageParser.java   |  2 +-
 .../java/org/apache/tika/detect/apple/IWorkDetectorTest.java   |  4 ++--
 .../apache/tika/parser/microsoft/ooxml/TruncatedOOXMLTest.java |  6 +++---
 .../src/main/java/org/apache/tika/parser/epub/EpubParser.java  |  2 +-
 .../src/main/java/org/apache/tika/parser/wacz/WACZParser.java  |  2 +-
 .../apache/tika/detect/zip/DefaultZipContainerDetector.java    | 10 +++++-----
 .../src/main/java/org/apache/tika/zip/utils/ZipSalvager.java   |  6 ++++--
 8 files changed, 18 insertions(+), 16 deletions(-)

diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork13PackageParser.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork13PackageParser.java
index 59619d8b5..da946c130 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork13PackageParser.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork13PackageParser.java
@@ -91,7 +91,7 @@ public class IWork13PackageParser extends AbstractParser {
             if (container instanceof ZipFile) {
                 zipFile = (ZipFile) container;
             } else if (tis.hasFile()) {
-                zipFile = new ZipFile(tis.getFile());
+                zipFile = ZipFile.builder().setFile(tis.getFile()).get();
             } else {
                 zipStream = new ZipInputStream(stream);
             }
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork18PackageParser.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork18PackageParser.java
index 78d379ccc..54ba71249 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork18PackageParser.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/main/java/org/apache/tika/parser/iwork/iwana/IWork18PackageParser.java
@@ -67,7 +67,7 @@ public class IWork18PackageParser extends AbstractParser {
             if (container instanceof ZipFile) {
                 zipFile = (ZipFile) container;
             } else if (tis.hasFile()) {
-                zipFile = new ZipFile(tis.getFile());
+                zipFile = ZipFile.builder().setFile(tis.getFile()).get();
             } else {
                 zipStream = new ZipInputStream(stream);
             }
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/detect/apple/IWorkDetectorTest.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/detect/apple/IWorkDetectorTest.java
index 42abe634c..c1d174290 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/detect/apple/IWorkDetectorTest.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/detect/apple/IWorkDetectorTest.java
@@ -34,7 +34,7 @@ public class IWorkDetectorTest extends TikaTest {
         String testFile = "/test-documents/testKeynote2013.detect";
         IWorkDetector detector = new IWorkDetector();
         try (TikaInputStream tis = 
TikaInputStream.get(getResourceAsStream(testFile));
-                ZipFile zipFile = new ZipFile(tis.getFile())) {
+                 ZipFile zipFile = 
ZipFile.builder().setFile(tis.getFile()).get()) {
             MediaType result = detector.detect(zipFile, tis);
             assertEquals(IWork13DocumentType.KEYNOTE13.getType(), result);
         }
@@ -45,7 +45,7 @@ public class IWorkDetectorTest extends TikaTest {
         String testFile = "/test-documents/testKeynote2018.key";
         IWorkDetector detector = new IWorkDetector();
         try (TikaInputStream tis = 
TikaInputStream.get(getResourceAsStream(testFile));
-                ZipFile zipFile = new ZipFile(tis.getFile())) {
+                 ZipFile zipFile = 
ZipFile.builder().setFile(tis.getFile()).get()) {
             MediaType result = detector.detect(zipFile, tis);
             assertEquals(IWork18DocumentType.KEYNOTE18.getType(), result);
         }
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/ooxml/TruncatedOOXMLTest.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/ooxml/TruncatedOOXMLTest.java
index 86de20d79..179f3106f 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/ooxml/TruncatedOOXMLTest.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/ooxml/TruncatedOOXMLTest.java
@@ -69,7 +69,7 @@ public class TruncatedOOXMLTest extends TikaTest {
             assertEquals(targetLength, bos.toByteArray().length);
         }
         try {
-            InputStream is = truncate("testWORD_various.docx", length + 1);
+            truncate("testWORD_various.docx", length + 1);
             fail("should have thrown EOF");
         } catch (EOFException e) {
             //swallow
@@ -93,7 +93,7 @@ public class TruncatedOOXMLTest extends TikaTest {
             }
             try (InputStream is = new FileInputStream(f)) {
                 ZipArchiveInputStream zipArchiveInputStream = new 
ZipArchiveInputStream(is);
-                ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry();
+                ZipArchiveEntry zae = zipArchiveInputStream.getNextEntry();
                 int cnt = 0;
                 while (zae != null && !zae.isDirectory() && ++cnt <= 10) {
                     System.out.println(f.getName() + " : " + zae.getName());
@@ -102,7 +102,7 @@ public class TruncatedOOXMLTest extends TikaTest {
                         IOUtils.copy(zipArchiveInputStream, bos);
                         System.out.println(new String(bos.toByteArray(), 
StandardCharsets.UTF_8));
                     }
-                    zae = zipArchiveInputStream.getNextZipEntry();
+                    zae = zipArchiveInputStream.getNextEntry();
                 }
             } catch (Exception e) {
                 System.out.println(f.getName() + " : " + e.getMessage());
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/epub/EpubParser.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/epub/EpubParser.java
index a67cb5c14..054752879 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/epub/EpubParser.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/epub/EpubParser.java
@@ -241,7 +241,7 @@ public class EpubParser extends AbstractParser {
             Path salvaged =
                     
resources.createTempFile(FilenameUtils.getSuffixFromPath(brokenZip.getFileName().toString()));
             ZipSalvager.salvageCopy(brokenZip.toFile(), salvaged.toFile());
-            try (ZipFile zipFile = new ZipFile(salvaged.toFile())) {
+            try (ZipFile zipFile = 
ZipFile.builder().setFile(salvaged.toFile()).get()) {
                 return bufferedParseZipFile(zipFile, bodyHandler, xhtml, 
metadata, context, false);
             } catch (EpubZipException e) {
                 try (InputStream is = TikaInputStream.get(salvaged)) {
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-webarchive-module/src/main/java/org/apache/tika/parser/wacz/WACZParser.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-webarchive-module/src/main/java/org/apache/tika/parser/wacz/WACZParser.java
index c81f8c89e..50552d7ce 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-webarchive-module/src/main/java/org/apache/tika/parser/wacz/WACZParser.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-webarchive-module/src/main/java/org/apache/tika/parser/wacz/WACZParser.java
@@ -66,7 +66,7 @@ public class WACZParser extends AbstractParser {
         if (stream instanceof TikaInputStream) {
             ZipFile zip = (ZipFile) ((TikaInputStream) 
stream).getOpenContainer();
             if (zip == null && ((TikaInputStream)stream).hasFile()) {
-                zip = new ZipFile(((TikaInputStream)stream).getFile());
+                zip = ZipFile.builder().setFile(((TikaInputStream) 
stream).getFile()).get();
             }
             if (zip != null) {
                 try {
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/detect/zip/DefaultZipContainerDetector.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/detect/zip/DefaultZipContainerDetector.java
index 824e03917..9adfe9ba0 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/detect/zip/DefaultZipContainerDetector.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/detect/zip/DefaultZipContainerDetector.java
@@ -207,7 +207,7 @@ public class DefaultZipContainerDetector implements 
Detector {
     private MediaType detectZipFormatOnFile(TikaInputStream tis, Metadata 
metadata) {
         ZipFile zip = null;
         try {
-            zip = new ZipFile(tis.getFile()); // TODO: hasFile()?
+            zip = ZipFile.builder().setFile(tis.getFile()).get(); // TODO: 
hasFile()?
 
             for (ZipContainerDetector zipDetector : getDetectors()) {
                 MediaType type = zipDetector.detect(zip, tis);
@@ -267,14 +267,14 @@ public class DefaultZipContainerDetector implements 
Detector {
             throws IOException {
         StreamingDetectContext detectContext = new StreamingDetectContext();
         try (ZipArchiveInputStream zis = new ZipArchiveInputStream(
-                new CloseShieldInputStream(input), "UTF8", false, 
allowStoredEntries)) {
-            ZipArchiveEntry zae = zis.getNextZipEntry();
+                CloseShieldInputStream.wrap(input), "UTF8", false, 
allowStoredEntries)) {
+            ZipArchiveEntry zae = zis.getNextEntry();
             while (zae != null) {
                 MediaType mt = detect(zae, zis, detectContext);
                 if (mt != null) {
                     return mt;
                 }
-                zae = zis.getNextZipEntry();
+                zae = zis.getNextEntry();
             }
         } catch (UnsupportedZipFeatureException zfe) {
             if (allowStoredEntries == false &&
@@ -319,7 +319,7 @@ public class DefaultZipContainerDetector implements 
Detector {
         if (loader != null && loader.isDynamic()) {
             List<ZipContainerDetector> dynamicDetectors =
                     
loader.loadDynamicServiceProviders(ZipContainerDetector.class);
-            if (dynamicDetectors.size() > 0) {
+            if (!dynamicDetectors.isEmpty()) {
                 List<ZipContainerDetector> zipDetectors = new 
ArrayList<>(staticZipDetectors);
                 zipDetectors.addAll(dynamicDetectors);
                 return zipDetectors;
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/zip/utils/ZipSalvager.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/zip/utils/ZipSalvager.java
index 9c2716309..1e3be2989 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/zip/utils/ZipSalvager.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-zip-commons/src/main/java/org/apache/tika/zip/utils/ZipSalvager.java
@@ -49,6 +49,8 @@ public class ZipSalvager {
      *
      * @param brokenZip
      * @param salvagedZip
+     * @param allowStoredEntries
+     * @throws java.io.IOException
      */
     public static void salvageCopy(InputStream brokenZip, File salvagedZip,
                                    boolean allowStoredEntries) throws 
IOException {
@@ -62,7 +64,7 @@ public class ZipSalvager {
                     ZipArchiveInputStream zipArchiveInputStream = new 
ZipArchiveInputStream(
                             new CloseShieldInputStream(brokenZip), "UTF8", 
false,
                             allowStoredEntries)) {
-                ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry();
+                ZipArchiveEntry zae = zipArchiveInputStream.getNextEntry();
                 try {
                     processZAE(zae, zipArchiveInputStream, outputStream);
                 } catch (UnsupportedZipFeatureException uzfe) {
@@ -118,7 +120,7 @@ public class ZipSalvager {
                     break;
                 }
             }
-            zae = zipArchiveInputStream.getNextZipEntry();
+            zae = zipArchiveInputStream.getNextEntry();
         }
     }
 

Reply via email to