BaseFixedLengthImporter extends BaseTextImporter { protected List<Integer> parseFieldLengths(String fieldLengths) { try { String[] lengths = fieldLengths.split(","); List<Integer> result = new ArrayList<>(); for (String s : lengths) { Integer len = Integer.valueOf(s); result.add(len); } return result; } catch (NumberFormatException ex) { throw new OCSImportException("Invalid field length entered", ex); } }  @Override int countRows(byte[] bytes, int sheetIndex);  }
@Test public void testParseFieldLengths() { List<Integer> list = importer.parseFieldLengths("1,2,3,4"); assertEquals(Lists.newArrayList(1, 2, 3, 4), list); }
@Test public void testParseFieldLengths_Error() { try { importer.parseFieldLengths("1,a,3,4"); } catch (OCSImportException ex) { assertEquals("Invalid field length entered", ex.getMessage()); } }