class ExportKeys implements Command {

    @Override
    public void run() throws Exception {
        try (PrintWriter writer = new PrintWriter(outputFileName, Constant.CHARSET.name())) {
            writer.print("");

            TableInfo tableInfo = new TableInfo(admin, args.getTableName(), args);
            tableInfo.refresh();
            Set<HRegionInfo> regions = tableInfo.getRegionInfoSet();

            int exported = 0, storeFileSizeMBSum = 0;
            for (HRegionInfo regionInfo : regions) {
                System.out.println(regionInfo.toString());

                if (args.getOptionSet().has(Args.OPTION_OPTIMIZE)) {
                    storeFileSizeMBSum += tableInfo.getRegionLoad(regionInfo).getStorefileSizeMB();
                    if (storeFileSizeMBSum < exportThreshold) {
                        continue;
                    }
                }
                if (export(writer, regionInfo)) exported++;
                storeFileSizeMBSum = 0;
            }

            System.out.println("\n" + regions.size() + " regions are scanned.");
            System.out.println(exported + " startkeys are exported.");
            System.out.println("\n" + outputFileName + " file is successfully created.");
        }
    }

    public  ExportKeys(HBaseAdmin admin, Args args);

}