Skip to content

Commit

Permalink
[#228] Added logging support to XLSStreamReaderAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Grigorev committed Jan 7, 2025
1 parent ea2e584 commit aba244e
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.spipes.modules.util;

import cz.cvut.spipes.modules.ResourceFormat;
import cz.cvut.spipes.modules.TabularModule;
import cz.cvut.spipes.modules.exception.SheetDoesntExistsException;
import cz.cvut.spipes.modules.model.Region;
import cz.cvut.spipes.registry.StreamResource;
Expand All @@ -11,6 +12,8 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -25,6 +28,7 @@ public class XLSStreamReaderAdapter implements StreamReaderAdapter {
private Sheet sheet;
private Iterator<org.apache.poi.ss.usermodel.Row> rowIterator;
Boolean skipHeader;
private static final Logger LOG = LoggerFactory.getLogger(XLSStreamReaderAdapter.class);

@Override
public void initialise(InputStream inputStream, ResourceFormat sourceResourceFormat, int tableIndex,
Expand All @@ -36,6 +40,10 @@ public void initialise(InputStream inputStream, ResourceFormat sourceResourceFor
workbook = new XSSFWorkbook(inputStream);
}
if ((tableIndex > workbook.getNumberOfSheets()) || (tableIndex < 1)) {
LOG.error("Requested sheet doesn't exist, number of sheets in the doc: {}, requested sheet: {}",
workbook.getNumberOfSheets(),
tableIndex
);
throw new SheetDoesntExistsException("Requested sheet doesn't exists.");
}
sheet = workbook.getSheetAt(tableIndex - 1);
Expand Down

0 comments on commit aba244e

Please sign in to comment.