/** * Returns integer if parsed successfully and it is valid otherwise prints * error and usage and then exits * * @param number * @return count */ private static int validateAndGetCount(String number) { int result = 0; try { result = Integer.parseInt(number); if (result < 3) { System.err.println(COUNT_ERR_MSG); printUsageThenExit(); } } catch (NumberFormatException e) { System.err .println("'" + number + "' can not be parsed to integer."); printUsageThenExit(); } return result; }
/** * validates file existence and returns the file * * @param path * @return File */ private static File validateAndGetFile(String path) { File file = new File(path); if (!file.exists()) { System.err.println("Path '" + file.getAbsolutePath() + "' does not exist. "); printUsageThenExit(); } return file; }
/** * validates file existence and returns the file * * @param path * @return File */ private static File validateAndGetFile(String path) { File file = new File(path); if (!file.exists()) { System.err.println("Path '" + file.getAbsolutePath() + "' does not exist. "); printUsageThenExit(); } return file; }
/** * Returns integer if parsed successfully and it is valid otherwise prints * error and usage and then exits * * @param number * @return count */ private static int validateAndGetCount(String number) { int result = 0; try { result = Integer.parseInt(number); if (result < 3) { System.err.println(COUNT_ERR_MSG); printUsageThenExit(); } } catch (NumberFormatException e) { System.err .println("'" + number + "' can not be parsed to integer."); printUsageThenExit(); } return result; }
/** * @param args dataLogDir [snapDir] -n count * dataLogDir -- path to the txn log directory * snapDir -- path to the snapshot directory * count -- the number of old snaps/logs you want to keep, value should be greater than or equal to 3<br> */ public static void main(String[] args) throws IOException { if (args.length < 3 || args.length > 4) { printUsageThenExit(); } File dataDir = validateAndGetFile(args[0]); File snapDir = dataDir; int num = -1; String countOption = ""; if (args.length == 3) { countOption = args[1]; num = validateAndGetCount(args[2]); } else { snapDir = validateAndGetFile(args[1]); countOption = args[2]; num = validateAndGetCount(args[3]); } if (!"-n".equals(countOption)) { printUsageThenExit(); } purge(dataDir, snapDir, num); }
/** * @param args dataLogDir [snapDir] -n count * dataLogDir -- path to the txn log directory * snapDir -- path to the snapshot directory * count -- the number of old snaps/logs you want to keep, value should be greater than or equal to 3<br> */ public static void main(String[] args) throws IOException { if (args.length < 3 || args.length > 4) { printUsageThenExit(); } File dataDir = validateAndGetFile(args[0]); File snapDir = dataDir; int num = -1; String countOption = ""; if (args.length == 3) { countOption = args[1]; num = validateAndGetCount(args[2]); } else { snapDir = validateAndGetFile(args[1]); countOption = args[2]; num = validateAndGetCount(args[3]); } if (!"-n".equals(countOption)) { printUsageThenExit(); } purge(dataDir, snapDir, num); }