@@ -39,9 +39,10 @@ public class ExcelConverterImpl implements ExcelConverter {
3939 * @throws IllegalAccessException {@inheritDoc}
4040 * @throws IOException {@inheritDoc}
4141 * @throws FileAlreadyExistsException {@inheritDoc}
42+ * @throws ExtensionNotValidException {@inheritDoc}
4243 */
4344 @ Override
44- public File objectsToExcel (List <?> objects , Class <?> clazz ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
45+ public File objectsToExcel (List <?> objects , Class <?> clazz ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
4546 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), clazz .getSimpleName (), Extension .XLSX , true );
4647 }
4748
@@ -55,9 +56,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz) throws IllegalAccess
5556 * @throws IllegalAccessException {@inheritDoc}
5657 * @throws IOException {@inheritDoc}
5758 * @throws FileAlreadyExistsException {@inheritDoc}
59+ * @throws ExtensionNotValidException {@inheritDoc}
5860 */
5961 @ Override
60- public File objectsToExcel (List <?> objects , Class <?> clazz , String filename ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
62+ public File objectsToExcel (List <?> objects , Class <?> clazz , String filename ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
6163 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), filename , Extension .XLSX , true );
6264 }
6365
@@ -72,9 +74,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String filename) thr
7274 * @throws IllegalAccessException {@inheritDoc}
7375 * @throws IOException {@inheritDoc}
7476 * @throws FileAlreadyExistsException {@inheritDoc}
77+ * @throws ExtensionNotValidException {@inheritDoc}
7578 */
7679 @ Override
77- public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
80+ public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
7881 return objectsToExcel (objects , clazz , path , filename , Extension .XLSX , true );
7982 }
8083
@@ -90,9 +93,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String path, String
9093 * @throws IllegalAccessException {@inheritDoc}
9194 * @throws IOException {@inheritDoc}
9295 * @throws FileAlreadyExistsException {@inheritDoc}
96+ * @throws ExtensionNotValidException {@inheritDoc}
9397 */
9498 @ Override
95- public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
99+ public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
96100 return objectsToExcel (objects , clazz , path , filename , Extension .XLSX , writeHeader );
97101 }
98102
@@ -106,9 +110,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String path, String
106110 * @throws IllegalAccessException {@inheritDoc}
107111 * @throws IOException {@inheritDoc}
108112 * @throws FileAlreadyExistsException {@inheritDoc}
113+ * @throws ExtensionNotValidException {@inheritDoc}
109114 */
110115 @ Override
111- public File objectsToExcel (List <?> objects , Class <?> clazz , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
116+ public File objectsToExcel (List <?> objects , Class <?> clazz , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
112117 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), clazz .getSimpleName (), Extension .XLSX , writeHeader );
113118 }
114119
@@ -123,9 +128,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, Boolean writeHeader)
123128 * @throws IllegalAccessException {@inheritDoc}
124129 * @throws IOException {@inheritDoc}
125130 * @throws FileAlreadyExistsException {@inheritDoc}
131+ * @throws ExtensionNotValidException {@inheritDoc}
126132 */
127133 @ Override
128- public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
134+ public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
129135 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), filename , Extension .XLSX , writeHeader );
130136 }
131137
@@ -141,9 +147,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String filename, Boo
141147 * @throws IllegalAccessException {@inheritDoc}
142148 * @throws IOException {@inheritDoc}
143149 * @throws FileAlreadyExistsException {@inheritDoc}
150+ * @throws ExtensionNotValidException {@inheritDoc}
144151 */
145152 @ Override
146- public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
153+ public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
147154 return objectsToExcel (objects , clazz , path , filename , extension , true );
148155 }
149156
@@ -157,9 +164,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String path, String
157164 * @throws IllegalAccessException {@inheritDoc}
158165 * @throws IOException {@inheritDoc}
159166 * @throws FileAlreadyExistsException {@inheritDoc}
167+ * @throws ExtensionNotValidException {@inheritDoc}
160168 */
161169 @ Override
162- public File objectsToExcel (List <?> objects , Class <?> clazz , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
170+ public File objectsToExcel (List <?> objects , Class <?> clazz , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
163171 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), clazz .getSimpleName (), extension , true );
164172 }
165173
@@ -174,9 +182,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, Extension extension)
174182 * @throws IllegalAccessException {@inheritDoc}
175183 * @throws IOException {@inheritDoc}
176184 * @throws FileAlreadyExistsException {@inheritDoc}
185+ * @throws ExtensionNotValidException {@inheritDoc}
177186 */
178187 @ Override
179- public File objectsToExcel (List <?> objects , Class <?> clazz , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
188+ public File objectsToExcel (List <?> objects , Class <?> clazz , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
180189 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), clazz .getSimpleName (), extension , writeHeader );
181190 }
182191
@@ -191,9 +200,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, Extension extension,
191200 * @throws IllegalAccessException {@inheritDoc}
192201 * @throws IOException {@inheritDoc}
193202 * @throws FileAlreadyExistsException {@inheritDoc}
203+ * @throws ExtensionNotValidException {@inheritDoc}
194204 */
195205 @ Override
196- public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
206+ public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Extension extension ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
197207 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), filename , extension , true );
198208 }
199209
@@ -209,9 +219,10 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String filename, Ext
209219 * @throws IllegalAccessException {@inheritDoc}
210220 * @throws IOException {@inheritDoc}
211221 * @throws FileAlreadyExistsException {@inheritDoc}
222+ * @throws ExtensionNotValidException {@inheritDoc}
212223 */
213224 @ Override
214- public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
225+ public File objectsToExcel (List <?> objects , Class <?> clazz , String filename , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
215226 return objectsToExcel (objects , clazz , System .getProperty ("java.io.tmpdir" ), filename , extension , writeHeader );
216227 }
217228
@@ -227,9 +238,14 @@ public File objectsToExcel(List<?> objects, Class<?> clazz, String filename, Ext
227238 * @throws IllegalAccessException {@inheritDoc}
228239 * @throws IOException {@inheritDoc}
229240 * @throws FileAlreadyExistsException {@inheritDoc}
241+ * @throws ExtensionNotValidException {@inheritDoc}
230242 */
231243 @ Override
232- public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException {
244+ public File objectsToExcel (List <?> objects , Class <?> clazz , String path , String filename , Extension extension , Boolean writeHeader ) throws IllegalAccessException , IOException , FileAlreadyExistsException , ExtensionNotValidException {
245+ /* Check extension*/
246+ if (!extension .isExcelExtension ())
247+ throw new ExtensionNotValidException ("Select an extension for an Excel file" );
248+
233249 /* Open file */
234250 String pathname = this .getPathname (path , filename , extension );
235251 File file = new File (pathname );
@@ -552,7 +568,7 @@ public File csvToExcel(File fileInput, String path, String filename, Extension e
552568 workbook .write (fileOutputStream );
553569
554570 /* Close file */
555- excelWorkbookUtils .close (workbook , fileOutputStream );
571+ excelWorkbookUtils .close (workbook , fileOutputStream , csvReader );
556572
557573 return outputFile ;
558574 }
0 commit comments