ProcessingMapper extends Mapper<NullWritable, NullWritable, Text /*N1 input name*/, Text /*split output name*/> { protected String getProductName(Configuration jobConfig, String fileName) { String regex = jobConfig.get(JobConfigNames.OUTPUT_REGEX, "^(.*)$"); String replacement = jobConfig.get(JobConfigNames.OUTPUT_REPLACEMENT, "L2_of_$1"); String dateElement = jobConfig.get(JobConfigNames.OUTPUT_DATE_ELEMENT, null); String dateFormat = jobConfig.get(JobConfigNames.OUTPUT_DATE_FORMAT, null); try { String newProductName = FileUtils.getFilenameWithoutExtension(fileName); if (regex != null && replacement != null) { Matcher m = Pattern.compile(regex).matcher(newProductName); newProductName = m.replaceAll(replacement); if (dateElement != null && dateFormat != null) { final String dateString = m.replaceAll(dateElement); final DateFormat df1 = DateUtils.createDateFormat(dateFormat); final DateFormat df2 = DateUtils.createDateFormat(newProductName); final Date date = df1.parse(dateString); newProductName = df2.format(date); } LOG.info("output name for " + fileName + " set to " + newProductName); } return newProductName; } catch (Exception e) { if (dateElement == null || dateFormat == null) { throw new RuntimeException("failed to convert name " + fileName + " matching regex " + regex + " by " + replacement); } else { throw new RuntimeException("failed to convert name " + fileName + " matching regex " + regex + " date ele " + dateElement + " date format " + dateFormat + " by " + replacement); } } }  static void main(String args[]); @Override void run(Context context);  }
@Test public void getProductName() throws Exception { String input = "S3A_OL_1_EFR____20181001T022958_20181001T023258_20181002T090807_0179_036_203_1980_MAR_O_NT_002.SEN3"; String name = new ProcessingMapper().getProductName(new JobConf(), input + ".zip"); assertEquals("L2_of_" + input, name); }