MosaicFormatterMapper extends Mapper<NullWritable, NullWritable, NullWritable, NullWritable> { static int getPartitionNumber(String partFilename) { if (!partFilename.startsWith(PART_FILE_PREFIX)) { throw new IllegalArgumentException("part file name is not-conforming."); } String numberPart = partFilename.substring(PART_FILE_PREFIX.length()); try { Number partNumber = PART_FILE_NUMBER_FORMAT.parse(numberPart); return partNumber.intValue(); } catch (ParseException e) { throw new IllegalArgumentException("part file number can not be parsed."); } }  @Override void run(Context context);  }
@Test public void testGetPartitionNumber() throws Exception { assertEquals(0, MosaicFormatterMapper.getPartitionNumber("part-r-00000")); assertEquals(1, MosaicFormatterMapper.getPartitionNumber("part-r-00001")); assertEquals(15, MosaicFormatterMapper.getPartitionNumber("part-r-00015")); }