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

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e6a04b4921 add setOutputPassword for HSLFSlideShow and HWPFDocument 
(#1050)
e6a04b4921 is described below

commit e6a04b49211e23c704fcdbe524d99d2f4486b083
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Apr 23 20:04:02 2026 +0200

    add setOutputPassword for HSLFSlideShow and HWPFDocument (#1050)
    
    * Add tests for MainExtractorFactory and setOutputPassword to 
HSLFSlideShow/HWPFDocument
    
    Agent-Logs-Url: 
https://github.com/pjfanning/poi/sessions/c3e970da-a269-4a43-b2ce-1cabede8daee
    
    Co-authored-by: pjfanning <[email protected]>
    
    * Refactor password handling to avoid Biff8EncryptionKey manipulation; add 
updateEncryptionRecord overload
    
    Agent-Logs-Url: 
https://github.com/pjfanning/poi/sessions/badb4a65-eb67-4c7f-af19-c30f8f2b20aa
    
    Co-authored-by: pjfanning <[email protected]>
    
    * password clone array
    
    * update
    
    * Update HSLFSlideShowEncrypted.java
    
    * Update TestHSLFSlideShow.java
    
    * add tests
    
    ---------
    
    Co-authored-by: copilot-swe-agent[bot] 
<[email protected]>
    Co-authored-by: pjfanning <[email protected]>
---
 .../apache/poi/hslf/usermodel/HSLFSlideShow.java   |  17 +++
 .../poi/hslf/usermodel/HSLFSlideShowEncrypted.java |  30 ++++-
 .../poi/hslf/usermodel/HSLFSlideShowImpl.java      |  27 ++++-
 .../java/org/apache/poi/hwpf/HWPFDocumentCore.java |  31 ++++-
 .../poi/hslf/usermodel/TestHSLFSlideShow.java      |  50 ++++++++
 .../apache/poi/hwpf/usermodel/TestHWPFWrite.java   |  42 +++++++
 .../apache/poi/hssf/usermodel/HSSFWorkbook.java    |   2 +-
 .../poi/extractor/TestMainExtractorFactory.java    | 128 +++++++++++++++++++++
 8 files changed, 319 insertions(+), 8 deletions(-)

diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
index 1d8a1f3e18..283b8d6359 100644
--- 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
+++ 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
@@ -1246,6 +1246,23 @@ public final class HSLFSlideShow extends POIDocument 
implements SlideShow<HSLFSh
         getSlideShowImpl().write(newFile);
     }
 
+    /**
+     * Set the password to be used to password protect the slideshow when 
writing out.
+     * If {@code null} is passed any password previously set via this method 
is cleared;
+     * in that case the thread-level password from {@link 
org.apache.poi.hssf.record.crypto.Biff8EncryptionKey#getCurrentUserPassword()}
+     * is used (if set), otherwise the output will be unencrypted.
+     * <p>
+     * The password supplied to the constructor for reading an encrypted file 
is
+     * <em>not</em> automatically used as the output password.
+     * </p>
+     *
+     * @param password as a char array, or {@code null} to clear
+     * @since 6.0.0
+     */
+    public void setOutputPassword(final char[] password) {
+        getSlideShowImpl().setOutputPassword(password);
+    }
+
     @Override
     public DocumentSummaryInformation getDocumentSummaryInformation() {
         return getSlideShowImpl().getDocumentSummaryInformation();
diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
index 62853c7bc9..8243b044b1 100644
--- 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
+++ 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
@@ -384,8 +384,34 @@ public class HSLFSlideShowEncrypted implements Closeable {
         }
     }
 
-    protected org.apache.poi.hslf.record.Record[] 
updateEncryptionRecord(org.apache.poi.hslf.record.Record[] records) {
-        String password = Biff8EncryptionKey.getCurrentUserPassword();
+    /**
+     * Updates the encryption record for the given records using the supplied 
password.
+     * If {@code password} is {@code null} any existing encryption record is 
removed (decrypted output).
+     *
+     * @param records  the current record array
+     * @param password the output password, or {@code null} to remove 
encryption
+     * @return the updated record array
+     * @since 6.0.0
+     */
+    protected org.apache.poi.hslf.record.Record[] updateEncryptionRecord(
+            org.apache.poi.hslf.record.Record[] records, char[] password) {
+        return updateEncryptionRecord(records, new String(password));
+    }
+
+    /**
+     * Updates the encryption record for the given records, reading the 
password from
+     * {@link Biff8EncryptionKey#getCurrentUserPassword()}.
+     *
+     * @param records the current record array
+     * @return the updated record array
+     */
+    protected org.apache.poi.hslf.record.Record[] updateEncryptionRecord(
+            org.apache.poi.hslf.record.Record[] records) {
+        return updateEncryptionRecord(records, 
Biff8EncryptionKey.getCurrentUserPassword());
+    }
+
+    private org.apache.poi.hslf.record.Record[] updateEncryptionRecord(
+            org.apache.poi.hslf.record.Record[] records, String password) {
         if (password == null) {
             if (dea == null) {
                 // no password given, no encryption record exits -> done
diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
index 2983369062..2bad0a7aa2 100644
--- 
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
+++ 
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
@@ -68,6 +68,7 @@ import org.apache.poi.hslf.record.PositionDependentRecord;
 import org.apache.poi.hslf.record.Record;
 import org.apache.poi.hslf.record.RecordTypes;
 import org.apache.poi.hslf.record.UserEditAtom;
+import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.poifs.crypt.EncryptionInfo;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentEntry;
@@ -111,6 +112,9 @@ public final class HSLFSlideShowImpl extends POIDocument 
implements Closeable {
     // Embedded objects stored in storage records in the document stream, 
lazily populated.
     private HSLFObjectData[] _objects;
 
+    // The password to use when writing out the slideshow (null = use 
Biff8EncryptionKey or no encryption)
+    private char[] _outputPassword;
+
     /**
      * @param length the max record length allowed for HSLFSlideShowImpl
      */
@@ -125,6 +129,23 @@ public final class HSLFSlideShowImpl extends POIDocument 
implements Closeable {
         return MAX_RECORD_LENGTH;
     }
 
+    /**
+     * Set the password to be used to password protect the slideshow when 
writing out.
+     * If {@code null} is passed any password previously set via this method 
is cleared;
+     * in that case the thread-level password from {@link 
Biff8EncryptionKey#getCurrentUserPassword()}
+     * is used (if set), otherwise the output will be unencrypted.
+     * <p>
+     * The password supplied to the constructor for reading an encrypted file 
is
+     * <em>not</em> automatically used as the output password.
+     * </p>
+     *
+     * @param password as a char array, or {@code null} to clear
+     * @since 6.0.0
+     */
+    public void setOutputPassword(final char[] password) {
+        this._outputPassword = password == null ? null : password.clone();
+    }
+
     /**
      * Constructs a Powerpoint document from fileName. Parses the document
      * and places all the important stuff into data structures.
@@ -868,7 +889,11 @@ public final class HSLFSlideShowImpl extends POIDocument 
implements Closeable {
 
         // set new encryption settings
         try (HSLFSlideShowEncrypted encryptedSS = new 
HSLFSlideShowEncrypted(getDocumentEncryptionAtom())) {
-            _records = encryptedSS.updateEncryptionRecord(_records);
+            if (_outputPassword != null) {
+                _records = encryptedSS.updateEncryptionRecord(_records, 
_outputPassword);
+            } else {
+                _records = encryptedSS.updateEncryptionRecord(_records);
+            }
 
             // Write out the Property Streams
             writeProperties(outFS, writtenEntries);
diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocumentCore.java 
b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocumentCore.java
index 2ea1224633..af2991b368 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocumentCore.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocumentCore.java
@@ -126,6 +126,8 @@ public abstract class HWPFDocumentCore extends POIDocument {
 
     private char[] _password;
 
+    private char[] _outputPasswordChars;
+
     private EncryptionInfo _encryptionInfo;
 
     protected HWPFDocumentCore() {
@@ -227,7 +229,7 @@ public abstract class HWPFDocumentCore extends POIDocument {
     public HWPFDocumentCore(DirectoryNode directory, final char[] password) 
throws IOException {
         // Sort out the hpsf properties
         super(directory);
-        _password = password;
+        _password = password == null ? null : password.clone();
 
         // read in the main stream.
         _mainStream = getDocumentEntryBytes(STREAM_WORD_DOCUMENT, 
FIB_BASE_LEN, Integer.MAX_VALUE);
@@ -309,6 +311,23 @@ public abstract class HWPFDocumentCore extends POIDocument 
{
         return _mainStream;
     }
 
+    /**
+     * Set the password to be used to password protect the document when 
writing out.
+     * If {@code null} is passed any password previously set via this method 
is cleared;
+     * in that case the thread-level password from {@link 
Biff8EncryptionKey#getCurrentUserPassword()}
+     * is used (if set), otherwise the output will be unencrypted.
+     * <p>
+     * The password supplied to the constructor for reading an encrypted file 
is
+     * <em>not</em> automatically used as the output password.
+     * </p>
+     *
+     * @param password as a char array, or {@code null} to clear
+     * @since 6.0.0
+     */
+    public void setOutputPassword(final char[] password) {
+        this._outputPasswordChars = password == null ? null : password.clone();
+    }
+
     @Override
     public EncryptionInfo getEncryptionInfo() throws IOException {
         if (_encryptionInfo != null) {
@@ -356,9 +375,13 @@ public abstract class HWPFDocumentCore extends POIDocument 
{
     protected void updateEncryptionInfo() {
         // make sure, that we've read all the streams ...
         readProperties();
-        // now check for the password
-        String password = _password == null
-                ? Biff8EncryptionKey.getCurrentUserPassword() : new 
String(_password);
+        // Resolve the output password: explicit setOutputPassword() takes 
priority,
+        // otherwise fall back to the thread-level Biff8EncryptionKey (if any).
+        // The password supplied to the constructor (_password) is 
intentionally NOT
+        // used as an output password.
+        String password = _outputPasswordChars != null
+                ? new String(_outputPasswordChars)
+                : Biff8EncryptionKey.getCurrentUserPassword();
         FibBase fBase = _fib.getFibBase();
         if (password == null) {
             fBase.setLKey(0);
diff --git 
a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
 
b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
index bfadc5e474..dc3eb63f34 100644
--- 
a/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
+++ 
b/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java
@@ -16,13 +16,18 @@
 ==================================================================== */
 package org.apache.poi.hslf.usermodel;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.sl.usermodel.BaseTestSlideShow;
+import org.apache.poi.sl.usermodel.PictureData;
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.junit.jupiter.api.Test;
 
@@ -38,6 +43,50 @@ public class TestHSLFSlideShow extends 
BaseTestSlideShow<HSLFShape, HSLFTextPara
         assertNotNull(createSlideShow());
     }
 
+    @Test
+    void setPassword() throws IOException {
+        final byte[] data = slTests.readFile("clock.jpg");
+        final String password = "123xyz";
+        try(UnsynchronizedByteArrayOutputStream baos = 
UnsynchronizedByteArrayOutputStream.builder().get()) {
+            try (HSLFSlideShow show = createSlideShow()) {
+                assertEquals(0, show.getPictureData().size());
+                PictureData picture = show.addPicture(data, 
PictureData.PictureType.JPEG);
+                assertEquals(1, show.getPictureData().size());
+                assertSame(picture, show.getPictureData().get(0));
+                show.setOutputPassword(password.toCharArray());
+                show.write(baos);
+            }
+            try (HSLFSlideShow show = new HSLFSlideShow(baos.toInputStream(), 
password.toCharArray())) {
+                assertEquals(1, show.getPictureData().size());
+                assertArrayEquals(data, 
show.getPictureData().get(0).getData());
+            }
+        }
+    }
+
+    @Test
+    void setPasswordBiff8() throws IOException {
+        final byte[] data = slTests.readFile("clock.jpg");
+        final String password = "123xyz";
+        // kept for legacy testing, prefer to set the password like the 
`setPassword` test does
+        try(UnsynchronizedByteArrayOutputStream baos = 
UnsynchronizedByteArrayOutputStream.builder().get()) {
+            try (HSLFSlideShow show = createSlideShow()) {
+                assertEquals(0, show.getPictureData().size());
+                PictureData picture = show.addPicture(data, 
PictureData.PictureType.JPEG);
+                assertEquals(1, show.getPictureData().size());
+                assertSame(picture, show.getPictureData().get(0));
+                Biff8EncryptionKey.setCurrentUserPassword(password);
+                show.write(baos);
+            }
+            Biff8EncryptionKey.setCurrentUserPassword(password);
+            try (HSLFSlideShow show = new HSLFSlideShow(baos.toInputStream())) 
{
+                assertEquals(1, show.getPictureData().size());
+                assertArrayEquals(data, 
show.getPictureData().get(0).getData());
+            }
+        } finally {
+            Biff8EncryptionKey.setCurrentUserPassword(null);
+        }
+    }
+
     @Override
     public HSLFSlideShow reopen(SlideShow<HSLFShape, HSLFTextParagraph> show) 
throws IOException {
         try (UnsynchronizedByteArrayOutputStream bos = 
UnsynchronizedByteArrayOutputStream.builder().get()) {
@@ -47,4 +96,5 @@ public class TestHSLFSlideShow extends 
BaseTestSlideShow<HSLFShape, HSLFTextPara
             }
         }
     }
+
 }
diff --git 
a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java 
b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
index 936b84317c..8f2a5a6441 100644
--- 
a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
+++ 
b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHWPFWrite.java
@@ -28,6 +28,7 @@ import java.io.InputStream;
 
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestCase;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
@@ -139,4 +140,45 @@ public final class TestHWPFWrite extends HWPFTestCase {
             assertThrows(IllegalStateException.class, doc::write);
         }
     }
+
+    @Test
+    void testPassword() throws IOException {
+        final String password = "password123";
+        UnsynchronizedByteArrayOutputStream baos = 
UnsynchronizedByteArrayOutputStream.builder().get();
+        try (HWPFDocument doc = 
HWPFTestDataSamples.openSampleFile("SampleDoc.doc")) {
+            Range r = doc.getRange();
+            assertEquals("I am a test document\r", r.getParagraph(0).text());
+            doc.setOutputPassword(password.toCharArray());
+            doc.write(baos);
+        }
+
+        try (HWPFDocument doc = new HWPFDocument(baos.toInputStream(), 
password.toCharArray())) {
+            Range r = doc.getRange();
+            assertEquals("I am a test document\r", r.getParagraph(0).text());
+        }
+    }
+
+    @Test
+    void testPasswordBiff8() throws IOException {
+        final String password = "password123";
+        // this tests the legacy way to use a password when writing or reading 
a file
+        // prefer the 6.0.0+ supported approach in `testPassword` test above
+        try(UnsynchronizedByteArrayOutputStream baos = 
UnsynchronizedByteArrayOutputStream.builder().get()) {
+            try (HWPFDocument doc = 
HWPFTestDataSamples.openSampleFile("SampleDoc.doc")) {
+                Range r = doc.getRange();
+                assertEquals("I am a test document\r", 
r.getParagraph(0).text());
+                Biff8EncryptionKey.setCurrentUserPassword(password);
+                doc.write(baos);
+            }
+
+            Biff8EncryptionKey.setCurrentUserPassword(password);
+            try (HWPFDocument doc = new HWPFDocument(baos.toInputStream())) {
+                Range r = doc.getRange();
+                assertEquals("I am a test document\r", 
r.getParagraph(0).text());
+            }
+        } finally {
+            Biff8EncryptionKey.setCurrentUserPassword(null);
+        }
+    }
+
 }
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java 
b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 21cbb9ca6d..9862b38d5d 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -1577,7 +1577,7 @@ public final class HSSFWorkbook extends POIDocument 
implements Workbook {
      * @since 6.0.0
      */
     public void setOutputPassword(final char[] password) {
-        this.outputPasswordChars = password;
+        this.outputPasswordChars = password == null ? null : password.clone();
     }
 
     /**
diff --git 
a/poi/src/test/java/org/apache/poi/extractor/TestMainExtractorFactory.java 
b/poi/src/test/java/org/apache/poi/extractor/TestMainExtractorFactory.java
new file mode 100644
index 0000000000..85b553cb64
--- /dev/null
+++ b/poi/src/test/java/org/apache/poi/extractor/TestMainExtractorFactory.java
@@ -0,0 +1,128 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.extractor;
+
+import static org.apache.poi.POITestCase.assertContains;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link MainExtractorFactory} password support.
+ */
+class TestMainExtractorFactory {
+
+    private static final POIDataSamples SS_SAMPLES = 
POIDataSamples.getSpreadSheetInstance();
+
+    private static final String PASSWORD_XLS = "password.xls";
+    private static final String PASSWORD = "password";
+
+    @Test
+    void testCreateFromFileWithPassword() throws IOException {
+        File file = SS_SAMPLES.getFile(PASSWORD_XLS);
+        MainExtractorFactory factory = new MainExtractorFactory();
+        try (POITextExtractor extractor = factory.create(file, PASSWORD)) {
+            assertNotNull(extractor);
+            assertContains(extractor.getText(), "ZIP");
+        }
+    }
+
+    @Test
+    void testCreateFromInputStreamWithPassword() throws IOException {
+        MainExtractorFactory factory = new MainExtractorFactory();
+        try (InputStream is = SS_SAMPLES.openResourceAsStream(PASSWORD_XLS);
+             POITextExtractor extractor = factory.create(is, PASSWORD)) {
+            assertNotNull(extractor);
+            assertContains(extractor.getText(), "ZIP");
+        }
+    }
+
+    @Test
+    void testCreateFromDirectoryWithPassword() throws IOException {
+        File file = SS_SAMPLES.getFile(PASSWORD_XLS);
+        MainExtractorFactory factory = new MainExtractorFactory();
+        try (POIFSFileSystem fs = new POIFSFileSystem(file, true);
+             POITextExtractor extractor = factory.create(fs.getRoot(), 
PASSWORD)) {
+            assertNotNull(extractor);
+            assertContains(extractor.getText(), "ZIP");
+        }
+    }
+
+    @Test
+    void testCreateWithNullPasswordUsesNoPassword() throws IOException {
+        // A non-encrypted file should be readable with null password
+        File file = SS_SAMPLES.getFile("Simple.xls");
+        MainExtractorFactory factory = new MainExtractorFactory();
+        try (POITextExtractor extractor = factory.create(file, null)) {
+            assertNotNull(extractor);
+            assertContains(extractor.getText(), "Sheet1");
+        }
+    }
+
+    @Test
+    void testBiff8EncryptionKeyCurrentUserPassword() {
+        // Verify the ThreadLocal get/set/clear behaviour
+        assertNull(Biff8EncryptionKey.getCurrentUserPassword());
+
+        Biff8EncryptionKey.setCurrentUserPassword("test");
+        assertNotNull(Biff8EncryptionKey.getCurrentUserPassword());
+        assertContains(Biff8EncryptionKey.getCurrentUserPassword(), "test");
+
+        // Clearing with null
+        Biff8EncryptionKey.setCurrentUserPassword(null);
+        assertNull(Biff8EncryptionKey.getCurrentUserPassword());
+    }
+
+    @Test
+    void testCreateEventBasedExtractorWithPassword() throws IOException {
+        ExtractorFactory.setThreadPrefersEventExtractors(true);
+        try {
+            File file = SS_SAMPLES.getFile(PASSWORD_XLS);
+            MainExtractorFactory factory = new MainExtractorFactory();
+            try (POITextExtractor extractor = factory.create(file, PASSWORD)) {
+                assertNotNull(extractor);
+                assertContains(extractor.getText(), "ZIP");
+            }
+        } finally {
+            ExtractorFactory.removeThreadPrefersEventExtractorsSetting();
+        }
+    }
+
+    @Test
+    void testCreateEventBasedExtractorFromInputStreamWithPassword() throws 
IOException {
+        ExtractorFactory.setThreadPrefersEventExtractors(true);
+        try {
+            MainExtractorFactory factory = new MainExtractorFactory();
+            try (InputStream is = 
SS_SAMPLES.openResourceAsStream(PASSWORD_XLS);
+                 POITextExtractor extractor = factory.create(is, PASSWORD)) {
+                assertNotNull(extractor);
+                assertContains(extractor.getText(), "ZIP");
+            }
+        } finally {
+            ExtractorFactory.removeThreadPrefersEventExtractorsSetting();
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to