public static void main ( String [ ] args ) { BasicConfigurator . configure ( new ConsoleAppender ( new PatternLayout ( "%d [%-25t] %-5p: %m%n" ) ) ) ; CmdLineParser parser = new CmdLineParser ( ) ; CmdLineParser . Option help = parser . addBooleanOption ( ' ' , "help" ) ; CmdLineParser . Option output = parser . addStringOption ( ' ' , "output" ) ; CmdLineParser . Option iface = parser . addStringOption ( ' ' , "iface" ) ; CmdLineParser . Option seedTime = parser . addIntegerOption ( ' ' , "seed" ) ; CmdLineParser . Option maxUpload = parser . addDoubleOption ( ' ' , "max-upload" ) ; CmdLineParser . Option maxDownload = parser . addDoubleOption ( ' ' , "max-download" ) ; try { parser . parse ( args ) ; } catch ( CmdLineParser . OptionException oe ) { System . err . println ( oe . getMessage ( ) ) ; usage ( System . err ) ; System . exit ( 1 ) ; } // Display help and exit if requested if ( Boolean . TRUE . equals ( ( Boolean ) parser . getOptionValue ( help ) ) ) { usage ( System . out ) ; System . exit ( 0 ) ; } String outputValue = ( String ) parser . getOptionValue ( output , DEFAULT_OUTPUT_DIRECTORY ) ; String ifaceValue = ( String ) parser . getOptionValue ( iface ) ; int seedTimeValue = ( Integer ) parser . getOptionValue ( seedTime , - 1 ) ; String [ ] otherArgs = parser . getRemainingArgs ( ) ; if ( otherArgs . length != 1 ) { usage ( System . err ) ; System . exit ( 1 ) ; } SimpleClient client = new SimpleClient ( ) ; try { Inet4Address iPv4Address = getIPv4Address ( ifaceValue ) ; File torrentFile = new File ( otherArgs [ 0 ] ) ; File outputFile = new File ( outputValue ) ; client . downloadTorrent ( torrentFile . getAbsolutePath ( ) , outputFile . getAbsolutePath ( ) , iPv4Address ) ; if ( seedTimeValue > 0 ) { Thread . sleep ( seedTimeValue * 1000 ) ; } } catch ( Exception e ) { logger . error ( "Fatal error: {}" , e . getMessage ( ) , e ) ; System . exit ( 2 ) ; } finally { client . stop ( ) ; } }
Main client entry point for stand - alone operation .