diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java index d36a0a4fad..f638a84d81 100644 --- a/src/java/org/apache/cassandra/tools/SSTableExport.java +++ b/src/java/org/apache/cassandra/tools/SSTableExport.java @@ -443,7 +443,13 @@ public static void export(Descriptor desc, String[] excludes) throws IOException * @param args command lines arguments * @throws ConfigurationException on configuration failure (wrong params given) */ - public static void main(String[] args) throws ConfigurationException, IOException + public static void main(String[] args) throws ConfigurationException + { + System.exit(mainInternal(args)); + } + + @SuppressWarnings("resource") + public static int mainInternal(String[] args) throws ConfigurationException { String usage = String.format("Usage: %s [-k key [-k key [...]] -x key [-x key [...]]]%n", SSTableExport.class.getName()); @@ -456,7 +462,7 @@ public static void main(String[] args) throws ConfigurationException, IOExceptio { System.err.println(e1.getMessage()); System.err.println(usage); - System.exit(1); + return 1; } @@ -464,7 +470,7 @@ public static void main(String[] args) throws ConfigurationException, IOExceptio { System.err.println("You must supply exactly one sstable or directory"); System.err.println(usage); - System.exit(1); + return 1; } Util.initDatabaseDescriptor(); @@ -476,7 +482,7 @@ public static void main(String[] args) throws ConfigurationException, IOExceptio if ((keys != null) && (keys.length > 0) && (prefix != null)) { System.err.println("Cannot specify keys and prefix at the same time"); - System.exit(1); + return 1; } File fileOrDirectory = new File(cmd.getArgs()[0]); @@ -500,20 +506,22 @@ public static void main(String[] args) throws ConfigurationException, IOExceptio i++; String ssTableFileName = file.getAbsolutePath(); printStream.printf("\"%s\":", file.getName()); - handleSingleSsTableFile(ssTableFileName, keys, excludes, prefix, printStream); + int res = handleSingleSsTableFile(ssTableFileName, keys, excludes, prefix, printStream); + if (res != 0) { + return res; + } } printStream.println("}"); } else { - handleSingleSsTableFile(fileOrDirectory.getAbsolutePath(), keys, excludes, prefix, printStream); + return handleSingleSsTableFile(fileOrDirectory.getAbsolutePath(), keys, excludes, prefix, printStream); } } - - System.exit(0); + return 0; } - private static void handleSingleSsTableFile(String ssTableFileName, String[] keys, String[] excludes, String prefix, PrintStream printStream) + private static int handleSingleSsTableFile(String ssTableFileName, String[] keys, String[] excludes, String prefix, PrintStream printStream) { Descriptor descriptor = Descriptor.fromFilename(ssTableFileName); @@ -522,7 +530,7 @@ private static void handleSingleSsTableFile(String ssTableFileName, String[] key { System.err.println(String.format("Filename %s references to nonexistent keyspace: %s!", ssTableFileName, descriptor.ksname)); - System.exit(1); + return 1; } Keyspace.setInitialized(); Keyspace keyspace = Keyspace.open(descriptor.ksname); @@ -545,7 +553,7 @@ private static void handleSingleSsTableFile(String ssTableFileName, String[] key { System.err.println(String.format("The provided table is not part of this cassandra keyspace: keyspace = %s, table = %s", descriptor.ksname, descriptor.cfname)); - System.exit(1); + return 1; } try @@ -569,6 +577,7 @@ else if (prefix != null) // throwing exception outside main with broken pipe causes windows cmd to hang e.printStackTrace(System.err); } + return 0; } private static void writeJSON(PrintStream out, Object value)