From: <ma...@us...> - 2012-08-27 14:15:56
|
Revision: 396 http://objectlabkit.svn.sourceforge.net/objectlabkit/?rev=396&view=rev Author: marchy Date: 2012-08-27 14:15:44 +0000 (Mon, 27 Aug 2012) Log Message: ----------- Improve the error messages Modified Paths: -------------- trunk/utils-excel/src/main/java/net/objectlab/kit/util/excel/Excel.java Modified: trunk/utils-excel/src/main/java/net/objectlab/kit/util/excel/Excel.java =================================================================== --- trunk/utils-excel/src/main/java/net/objectlab/kit/util/excel/Excel.java 2012-08-27 13:05:31 UTC (rev 395) +++ trunk/utils-excel/src/main/java/net/objectlab/kit/util/excel/Excel.java 2012-08-27 14:15:44 UTC (rev 396) @@ -19,6 +19,10 @@ private void init(InputStream inputStream) throws RuntimeException { + if (inputStream == null) { + throw new NullPointerException("inputStream cannot be null"); + } + try { workbook = WorkbookFactory.create(inputStream); } catch (Exception e) { @@ -62,13 +66,17 @@ * @param range either the range of the entire block to be read, or just the * top row of the cells, in which case the method will stop when * the first empty cell is reached in the first column - * @param colTypes An array of data types expected at each column. + * @param columnTypes An array of data types expected at each column. * If this array is shorter than the number of column, then the last * data type is used until the end. So if only one value is given, * then that is used for the entire block. */ - public Object[][] readBlock(String range, Class... colTypes) { + public Object[][] readBlock(String range, Class... columnTypes) { + if (columnTypes == null || columnTypes.length == 0) { + throw new RuntimeException("columnTypes cannot be null / empty"); + } + CellRangeAddress cra = CellRangeAddress.valueOf(range); AreaReference ar = new AreaReference(range); Sheet sheet = workbook.getSheet(ar.getFirstCell().getSheetName()); @@ -93,10 +101,10 @@ for (int colNum = 0; colNum < width; colNum++) { Class colType; - if (colNum < colTypes.length - 1) { - colType = colTypes[colNum]; + if (colNum < columnTypes.length - 1) { + colType = columnTypes[colNum]; } else { - colType = colTypes[colTypes.length - 1]; + colType = columnTypes[columnTypes.length - 1]; } Cell cell = row.getCell(firstColumn + colNum); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |