@@ -47,7 +47,7 @@ public HSSFEventFactory() {
4747 /**
4848 * Processes a file into essentially record events.
4949 *
50- * @param req an Instance of HSSFRequest which has your registered listeners
50+ * @param req an instance of HSSFRequest which has your registered listeners
5151 * @param fs a POIFS filesystem containing your workbook
5252 *
5353 * @throws IOException if the workbook contained errors
@@ -56,15 +56,45 @@ public void processWorkbookEvents(HSSFRequest req, POIFSFileSystem fs) throws IO
5656 processWorkbookEvents (req , fs .getRoot ());
5757 }
5858
59+ /**
60+ * Processes a file into essentially record events.
61+ *
62+ * @param req an instance of HSSFRequest which has your registered listeners
63+ * @param fs a POIFS filesystem containing your workbook
64+ * @param password in char array format (can be null)
65+ *
66+ * @throws IOException if the workbook contained errors
67+ * @since 6.0.0
68+ */
69+ public void processWorkbookEvents (HSSFRequest req , POIFSFileSystem fs ,
70+ final char [] password ) throws IOException {
71+ processWorkbookEvents (req , fs .getRoot (), password );
72+ }
73+
5974 /**
6075 * Processes a file into essentially record events.
6176 *
62- * @param req an Instance of HSSFRequest which has your registered listeners
77+ * @param req an instance of HSSFRequest which has your registered listeners
6378 * @param dir a DirectoryNode containing your workbook
6479 *
6580 * @throws IOException if the workbook contained errors
6681 */
6782 public void processWorkbookEvents (HSSFRequest req , DirectoryNode dir ) throws IOException {
83+ processWorkbookEvents (req , dir , null );
84+ }
85+
86+ /**
87+ * Processes a file into essentially record events.
88+ *
89+ * @param req an instance of HSSFRequest which has your registered listeners
90+ * @param dir a DirectoryNode containing your workbook
91+ * @param password in char array format (can be null)
92+ *
93+ * @throws IOException if the workbook contained errors
94+ * @since 6.0.0
95+ */
96+ public void processWorkbookEvents (HSSFRequest req , DirectoryNode dir ,
97+ final char [] password ) throws IOException {
6898 // some old documents have "WORKBOOK" or "BOOK"
6999 String name = null ;
70100 if (dir .hasEntry (WORKBOOK )) {
@@ -79,29 +109,45 @@ public void processWorkbookEvents(HSSFRequest req, DirectoryNode dir) throws IOE
79109 }
80110
81111 try (InputStream in = dir .createDocumentInputStream (name )) {
82- processEvents (req , in );
112+ processEvents (req , in , password );
83113 }
84114 }
85115
86- /**
87- * Processes a file into essentially record events.
88- *
89- * @param req an Instance of HSSFRequest which has your registered listeners
90- * @param fs a POIFS filesystem containing your workbook
91- * @return numeric user-specified result code.
92- *
93- * @throws HSSFUserException if the processing should be aborted
94- * @throws IOException if the workbook contained errors
95- */
96- public short abortableProcessWorkbookEvents (HSSFRequest req , POIFSFileSystem fs )
97- throws IOException , HSSFUserException {
98- return abortableProcessWorkbookEvents (req , fs .getRoot ());
99- }
116+ /**
117+ * Processes a file into essentially record events.
118+ *
119+ * @param req an instance of HSSFRequest which has your registered listeners
120+ * @param fs a POIFS filesystem containing your workbook
121+ * @return numeric user-specified result code.
122+ * @throws HSSFUserException if the processing should be aborted
123+ * @throws IOException if the workbook contained errors
124+ */
125+ public short abortableProcessWorkbookEvents (HSSFRequest req , POIFSFileSystem fs )
126+ throws IOException , HSSFUserException {
127+ return abortableProcessWorkbookEvents (req , fs .getRoot ());
128+ }
100129
101130 /**
102131 * Processes a file into essentially record events.
103132 *
104- * @param req an Instance of HSSFRequest which has your registered listeners
133+ * @param req an instance of HSSFRequest which has your registered listeners
134+ * @param fs a POIFS filesystem containing your workbook
135+ * @param password in char array format (can be null)
136+ * @return numeric user-specified result code.
137+ * @throws HSSFUserException if the processing should be aborted
138+ * @throws IOException if the workbook contained errors
139+ * @since 6.0.0
140+ */
141+ public short abortableProcessWorkbookEvents (HSSFRequest req , POIFSFileSystem fs ,
142+ final char [] password )
143+ throws IOException , HSSFUserException {
144+ return abortableProcessWorkbookEvents (req , fs .getRoot (), password );
145+ }
146+
147+ /**
148+ * Processes a file into essentially record events.
149+ *
150+ * @param req an instance of HSSFRequest which has your registered listeners
105151 * @param dir a DirectoryNode containing your workbook
106152 * @return numeric user-specified result code.
107153 *
@@ -115,6 +161,26 @@ public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir)
115161 }
116162 }
117163
164+ /**
165+ * Processes a file into essentially record events.
166+ *
167+ * @param req an instance of HSSFRequest which has your registered listeners
168+ * @param dir a DirectoryNode containing your workbook
169+ * @param password in char array format (can be null)
170+ * @return numeric user-specified result code.
171+ *
172+ * @throws HSSFUserException if the processing should be aborted
173+ * @throws IOException if the workbook contained errors
174+ * @since 6.0.0
175+ */
176+ public short abortableProcessWorkbookEvents (HSSFRequest req , DirectoryNode dir ,
177+ final char [] password )
178+ throws IOException , HSSFUserException {
179+ try (InputStream in = dir .createDocumentInputStream ("Workbook" )) {
180+ return abortableProcessEvents (req , in , password );
181+ }
182+ }
183+
118184 /**
119185 * Processes a DocumentInputStream into essentially Record events.
120186 *
@@ -123,47 +189,85 @@ public short abortableProcessWorkbookEvents(HSSFRequest req, DirectoryNode dir)
123189 * user code or <code>HSSFUserException</code> will be passed back.
124190 *
125191 * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
126- * @param req an Instance of HSSFRequest which has your registered listeners
192+ * @param req an instance of HSSFRequest which has your registered listeners
127193 * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
128194 */
129195 public void processEvents (HSSFRequest req , InputStream in ) {
130196 try {
131- genericProcessEvents (req , in );
197+ genericProcessEvents (req , in , null );
132198 } catch (HSSFUserException hue ) {
133199 /*If an HSSFUserException user exception is thrown, ignore it.*/
134200 }
135201 }
136202
203+ /**
204+ * Processes a DocumentInputStream into essentially Record events.
205+ *
206+ * If an <code>AbortableHSSFListener</code> causes a halt to processing during this call
207+ * the method will return just as with <code>abortableProcessEvents</code>, but no
208+ * user code or <code>HSSFUserException</code> will be passed back.
209+ *
210+ * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
211+ * @param req an instance of HSSFRequest which has your registered listeners
212+ * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
213+ * @param password in char array format (can be null)
214+ * @since 6.0.0
215+ */
216+ public void processEvents (HSSFRequest req , InputStream in , final char [] password ) {
217+ try {
218+ genericProcessEvents (req , in , password );
219+ } catch (HSSFUserException hue ) {
220+ /*If an HSSFUserException user exception is thrown, ignore it.*/
221+ }
222+ }
137223
138224 /**
139225 * Processes a DocumentInputStream into essentially Record events.
140226 *
141227 * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
142- * @param req an Instance of HSSFRequest which has your registered listeners
228+ * @param req an instance of HSSFRequest which has your registered listeners
143229 * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
144230 * @return numeric user-specified result code.
145231 *
146232 * @throws HSSFUserException if the processing should be aborted
147233 */
148234 public short abortableProcessEvents (HSSFRequest req , InputStream in )
149235 throws HSSFUserException {
150- return genericProcessEvents (req , in );
236+ return genericProcessEvents (req , in , null );
237+ }
238+
239+ /**
240+ * Processes a DocumentInputStream into essentially Record events.
241+ *
242+ * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
243+ * @param req an instance of HSSFRequest which has your registered listeners
244+ * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
245+ * @param password in char array format (can be null)
246+ * @return numeric user-specified result code.
247+ *
248+ * @throws HSSFUserException if the processing should be aborted
249+ * @since 6.0.0
250+ */
251+ public short abortableProcessEvents (HSSFRequest req , InputStream in , final char [] password )
252+ throws HSSFUserException {
253+ return genericProcessEvents (req , in , password );
151254 }
152255
153256 /**
154257 * Processes a DocumentInputStream into essentially Record events.
155258 *
156259 * @see org.apache.poi.poifs.filesystem.POIFSFileSystem#createDocumentInputStream(String)
157- * @param req an Instance of HSSFRequest which has your registered listeners
260+ * @param req an instance of HSSFRequest which has your registered listeners
158261 * @param in a DocumentInputStream obtained from POIFS's POIFSFileSystem object
159262 * @return numeric user-specified result code.
160263 */
161- private short genericProcessEvents (HSSFRequest req , InputStream in )
264+ private short genericProcessEvents (HSSFRequest req , InputStream in , final char [] password )
162265 throws HSSFUserException {
163266 short userCode = 0 ;
164267
165268 // Create a new RecordStream and use that
166- RecordFactoryInputStream recordStream = new RecordFactoryInputStream (in , false );
269+ RecordFactoryInputStream recordStream = new RecordFactoryInputStream (
270+ in , false , password );
167271
168272 // Process each record as they come in
169273 while (true ) {
0 commit comments