Source:
<code>public @ResponseBody List<ColumnDataDto> importSpreadsheet(@RequestParam("file") MultipartFile file) throws IOException { String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase(); SpreadsheetWrapper sheet = null; <START> if (extension.equals("xlsx")) { <END> sheet = new ExcelSpreadsheetWrapper(file.getInputStream()); } else if (extension.equals("ods")) { sheet = new OpenDocumentSpreadsheetWrapper(file.getInputStream()); } else if (extension.equals("csv")) { sheet = new DelimitedSpreadsheetWrapper(file.getInputStream()); } else { throw new RestException("Unknown file extension: " + extension + ". Only xlsx, ods, and csv files are accepted", Status.BAD_REQUEST); } int rows = sheet.getRowCount(); if (rows < 2) { throw new RestException("Spreadsheet contains no data to import", Status.BAD_REQUEST); } List<ColumnDataDto> columns = new ArrayList<>(); for (int i = 0; i < sheet.getColumnCount(); i++) { try { columns.add(new ColumnDataDto(sheet.getCellValue(0, i))); } catch (IllegalArgumentException e) { throw new RestException(String.format("Failed to parse heading cell at row 0, column %d", i), Status.BAD_REQUEST); } } for (int rowNum = 1; rowNum < sheet.getRowCount(); rowNum++) { for (int colNum = 0; colNum < sheet.getColumnCount(); colNum++) { try { columns.get(colNum).getData().add(sheet.getCellValue(rowNum, colNum)); } catch (IllegalArgumentException e) { throw new RestException(String.format("Failed to parse value of cell at row %d, column %d", rowNum, colNum), Status.BAD_REQUEST); } } } return columns; }</code><technical_language>If trouble of extracting extension, I more sense a switch block. That, bother do filename.endsWith(".xlsx")</technical_language>

Target:
public @ResponseBody List<ColumnDataDto> importSpreadsheet(@RequestParam("file") MultipartFile file) throws IOException { String extension = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1).toLowerCase(); SpreadsheetWrapper sheet = null; switch (extension) { case "xlsx": sheet = new ExcelSpreadsheetWrapper(file.getInputStream()); break; case "ods": sheet = new OpenDocumentSpreadsheetWrapper(file.getInputStream()); break; case "csv": sheet = new DelimitedSpreadsheetWrapper(file.getInputStream()); break; default: throw new RestException("Unknown file extension: " + extension + ". Only xlsx, ods, and csv files are accepted", Status.BAD_REQUEST); } int rows = sheet.getRowCount(); if (rows < 2) { throw new RestException("Spreadsheet contains no data to import", Status.BAD_REQUEST); } List<ColumnDataDto> columns = new ArrayList<>(); for (int i = 0; i < sheet.getColumnCount(); i++) { try { columns.add(new ColumnDataDto(sheet.getCellValue(0, i))); } catch (IllegalArgumentException e) { throw new RestException(String.format("Failed to parse heading cell at row 0, column %d", i), Status.BAD_REQUEST); } } for (int rowNum = 1; rowNum < sheet.getRowCount(); rowNum++) { for (int colNum = 0; colNum < sheet.getColumnCount(); colNum++) { try { columns.get(colNum).getData().add(sheet.getCellValue(rowNum, colNum)); } catch (IllegalArgumentException e) { throw new RestException(String.format("Failed to parse value of cell at row %d, column %d", rowNum, colNum), Status.BAD_REQUEST); } } } return columns; }