Skip to content

Commit

Permalink
Use try-with-resources or close this "XSSFWorkbook" in a "finally" cl…
Browse files Browse the repository at this point in the history
…ause
  • Loading branch information
RodrigoZambrana committed Dec 18, 2024
1 parent a0cda43 commit 0651448
Showing 1 changed file with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ public class ExcelUtils {
private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

/**
* Processes the census in the Excel file and returns it as a list of
* UserVoter
* Processes the census in the Excel file and returns it as a list of UserVoter
*
* @param contentType
* Excel type (xls or xlsx)
* @param census
* the file
* @param contentType Excel type (xls or xlsx)
* @param census the file
* @return the UserVoter list
* @throws CensusValidationException
*/
Expand Down Expand Up @@ -200,8 +197,7 @@ private static boolean isValid(String mail) {
/**
* Validate that required columns exist
*
* @param firstRow
* titles row
* @param firstRow titles row
* @return true if valid, false otherwise
*/
private static boolean validateRequiredColumns(Row firstRow) {
Expand Down Expand Up @@ -231,16 +227,11 @@ private static boolean validateRequiredColumns(Row firstRow) {
/**
* Validate that required fields are not null in given row
*
* @param row
* the row to check
* @param languageIndex
* the language column index
* @param nameIndex
* the name column index
* @param mailIndex
* the mail column index
* @param voteAmountIndex
* the voteAmount column index
* @param row the row to check
* @param languageIndex the language column index
* @param nameIndex the name column index
* @param mailIndex the mail column index
* @param voteAmountIndex the voteAmount column index
* @return true if valid, false otherwise
*/
private static boolean validateRequiredFields(Row row, int languageIndex, int nameIndex, int mailIndex, int voteAmountIndex) {
Expand All @@ -250,17 +241,14 @@ private static boolean validateRequiredFields(Row row, int languageIndex, int na
/**
* Export the list of voters to a xlsx Excel file
*
* @param userVoters
* the voters list
* @param fileName
* the file name
* @param userVoters the voters list
* @param fileName the file name
* @return the File object
*/
public static File exportToExcel(List<UserVoter> userVoters, String fileName) {
File file = new File(System.getProperty(TEMP_DIR).concat(fileName));

try {
XSSFWorkbook workbook = new XSSFWorkbook();
try (XSSFWorkbook workbook = new XSSFWorkbook()) {
XSSFSheet sheet = workbook.createSheet("Padron_Electoral");

int rowIndex = 0;
Expand Down

0 comments on commit 0651448

Please sign in to comment.