SequenceFilesFromMailArchives { public static void main(String[] args) throws Exception { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option parentOpt = obuilder.withLongName("input").withRequired(true).withArgument( abuilder.withName("input").withMinimum(1).withMaximum(1).create()).withDescription( "The input dir containing the documents").withShortName("i").create(); Option outputDirOpt = obuilder.withLongName("output").withRequired(true).withArgument( abuilder.withName("output").withMinimum(1).withMaximum(1).create()).withDescription( "The output directory").withShortName("o").create(); Option chunkSizeOpt = obuilder.withLongName("chunkSize").withArgument( abuilder.withName("chunkSize").withMinimum(1).withMaximum(1).create()).withDescription( "The chunkSize in MegaBytes. Defaults to 64").withShortName("chunk").create(); Option keyPrefixOpt = obuilder.withLongName("keyPrefix").withArgument( abuilder.withName("keyPrefix").withMinimum(1).withMaximum(1).create()).withDescription( "The prefix to be prepended to the key").withShortName("prefix").create(); Option charsetOpt = obuilder.withLongName("charset").withRequired(true).withArgument( abuilder.withName("charset").withMinimum(1).withMaximum(1).create()).withDescription( "The name of the character encoding of the input files").withShortName("c").create(); Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h") .create(); Group group = gbuilder.withName("Options").withOption(keyPrefixOpt).withOption(chunkSizeOpt).withOption( charsetOpt).withOption(outputDirOpt).withOption(helpOpt).withOption(parentOpt).create(); try { Parser parser = new Parser(); parser.setGroup(group); parser.setHelpOption(helpOpt); CommandLine cmdLine = parser.parse(args); if (cmdLine.hasOption(helpOpt)) { CommandLineUtil.printHelp(group); return; } File parentDir = new File((String) cmdLine.getValue(parentOpt)); String outputDir = (String) cmdLine.getValue(outputDirOpt); int chunkSize = 64; if (cmdLine.hasOption(chunkSizeOpt)) { chunkSize = Integer.parseInt((String) cmdLine.getValue(chunkSizeOpt)); } String prefix = ""; if (cmdLine.hasOption(keyPrefixOpt)) { prefix = (String) cmdLine.getValue(keyPrefixOpt); } Charset charset = Charset.forName((String) cmdLine.getValue(charsetOpt)); SequenceFilesFromMailArchives dir = new SequenceFilesFromMailArchives(); dir.createSequenceFiles(parentDir, outputDir, prefix, chunkSize, charset); } catch (OptionException e) { log.error("Exception", e); CommandLineUtil.printHelp(group); } }  void createSequenceFiles(File parentDir,
                                  String outputDir,
                                  String prefix,
                                  int chunkSizeInMB,
                                  Charset charset); static void main(String[] args);  }
@Test public void testMain() throws Exception { String[] args = { "--input", inputDir.getAbsolutePath(), "--output", outputDir.getAbsolutePath(), "--charset", "UTF-8", "--keyPrefix", "TEST" }; SequenceFilesFromMailArchives.main(args); File expectedChunkFile = new File(outputDir, "chunk-0"); String expectedChunkPath = expectedChunkFile.getAbsolutePath(); Assert.assertTrue("Expected chunk file "+expectedChunkPath+" not found!", expectedChunkFile.isFile()); Configuration conf = new Configuration(); SequenceFileIterator<Text,Text> iterator = new SequenceFileIterator<Text,Text>(new Path(expectedChunkPath), true, conf); Assert.assertTrue("First key/value pair not found!", iterator.hasNext()); Pair<Text,Text> record = iterator.next(); File parentFile = new File(new File(new File("TEST"), "subdir"), "mail-messages.gz"); Assert.assertEquals(new File(parentFile, testVars[0][0]).toString(), record.getFirst().toString()); Assert.assertEquals(testVars[0][1]+testVars[0][2], record.getSecond().toString()); Assert.assertTrue("Second key/value pair not found!", iterator.hasNext()); record = iterator.next(); Assert.assertEquals(new File(parentFile, testVars[1][0]).toString(), record.getFirst().toString()); Assert.assertEquals(testVars[1][1]+testVars[1][2], record.getSecond().toString()); Assert.assertFalse("Only two key/value pairs expected!", iterator.hasNext()); }