public static void main(String[] args) throws IOException { Path baseDir = null; String localPath = null; String preservePath = null; String sIgnoreTablesFilename = null; String sNoPreserveFilename = null; String sDateString = null; long size = 0; // UNIX dates for right now long now = new java.util.Date().getTime() / 1000; long maxDate = now; for (int i = 0; i < args.length; i++) { if (args[i].equals("--hdfs-path")) { baseDir = new Path(args[++i]); continue; } if (args[i].equals("--local-path")) { localPath = args[++i]; continue; } if (args[i].equals("--preserve-path")) { preservePath = args[++i]; continue; } if (args[i].equals("--no-preserve")) { sNoPreserveFilename = args[++i]; continue; } if (args[i].equals("--ignore-tables")) { sIgnoreTablesFilename = args[++i]; continue; } if (args[i].equals("--sleep")) { try { m_nSleepSeconds = Integer.parseInt(args[++i]); } catch (Exception e) { System.err.println("ERROR: " + e.toString() + "\n"); usage(); } continue; } if (args[i].equals("--dry-run")) { m_bDryRun = true; continue; } if (args[i].equals("--date")) { sDateString = args[++i]; continue; } if (args[i].equals("--max-date")) { maxDate = Long.parseLong(args[++i]); continue; } if (args[i].equals("--max-bytes")) { size = Long.parseLong(args[++i]); continue; } System.err.println("ERROR: unknown arg " + args[i]); usage(); } if (baseDir == null || localPath == null || preservePath == null || sDateString == null) { usage(); } long minDate; if ("yesterday".equals(sDateString)) { // figure out yesterday's dates Calendar cal = Calendar.getInstance(); cal.roll(Calendar.DAY_OF_YEAR, -1); // yesterday midnight cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); minDate = cal.getTimeInMillis() / 1000; // yesterday end of day cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 999); maxDate = cal.getTimeInMillis() / 1000; } else if ("last-week".equals(sDateString)) { minDate = maxDate - (7 * 24 * 60 * 60); } else if ("last-day".equals(sDateString)) { minDate = maxDate - (24 * 60 * 60); } else { // UNIX date since epoch of last backup minDate = Long.parseLong(sDateString); } long tmpDate = 0; BackupHdfs bak = new BackupHdfs(); // initialize the list of tables to ignore if (sIgnoreTablesFilename != null) { bak.initializeTablesToIgnore(sIgnoreTablesFilename); } // initialize list of files to not preserve if (sNoPreserveFilename != null) { bak.initializeNoPreserve(sNoPreserveFilename); } ArrayList<Path> pathList = new ArrayList<Path>(2000); HashMap<Path, Long> hmTimestamps = new HashMap<Path, Long>(); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); // If the HDFS path is a dir continue if (fs.getFileStatus(baseDir).isDir()) { Calendar cal = Calendar.getInstance(); System.err.println(""); cal.setTimeInMillis(minDate * 1000); System.err.println("min date = " + cal.getTime().toString()); cal.setTimeInMillis(maxDate * 1000); System.err.println("max date = " + cal.getTime().toString()); System.err.println(""); System.err.println("Searching filesystem: " + baseDir.toUri().getPath()); bak.checkDir(fs, minDate, maxDate, baseDir, pathList, hmTimestamps); System.err.println(""); System.err.println("Skipped " + m_nIgnoredTables + " files due to ignored tables"); System.err.println(""); System.err.println("Number of files to backup = " + pathList.size()); System.err.println("Total bytes to backup = " + prettyPrintBytes(m_nTotalBytes)); System.err.println(""); System.err.println("sorting list of files..."); Collections.sort(pathList, new DateComparator(hmTimestamps)); System.err.println("done"); System.err.println(""); System.err.println("starting backup..."); tmpDate = bak.backupFiles(localPath, preservePath, fs, pathList, size); bak.closeFiles(); System.err.println(""); System.err.println("backup completed..."); } if (tmpDate == 0) { // If not size limit reached print out date for right now System.out.println(maxDate); } else { // Print out date for last file backed up System.err.println("Size limit reached."); System.out.println(tmpDate); } System.exit(0); }
/** The main program for ReTrace. */ public static void main(String[] args) { if (args.length < 1) { System.err.println( "Usage: java proguard.ReTrace [-verbose] <mapping_file> [<stacktrace_file>]"); System.exit(-1); } String regularExpresssion = STACK_TRACE_EXPRESSION; boolean verbose = false; int argumentIndex = 0; while (argumentIndex < args.length) { String arg = args[argumentIndex]; if (arg.equals(REGEX_OPTION)) { regularExpresssion = args[++argumentIndex]; } else if (arg.equals(VERBOSE_OPTION)) { verbose = true; } else { break; } argumentIndex++; } if (argumentIndex >= args.length) { System.err.println( "Usage: java proguard.ReTrace [-regex <regex>] [-verbose] <mapping_file> [<stacktrace_file>]"); System.exit(-1); } File mappingFile = new File(args[argumentIndex++]); File stackTraceFile = argumentIndex < args.length ? new File(args[argumentIndex]) : null; ReTrace reTrace = new ReTrace(regularExpresssion, verbose, mappingFile, stackTraceFile); try { // Execute ReTrace with its given settings. reTrace.execute(); } catch (IOException ex) { if (verbose) { // Print a verbose stack trace. ex.printStackTrace(); } else { // Print just the stack trace message. System.err.println("Error: " + ex.getMessage()); } System.exit(1); } System.exit(0); }
public static void main(String[] args) { if (args.length == 0) { printDocs(); System.exit(0); } new ArupPipelineWrapper(args); }
public static void main(String[] args) { if (args.length < 1) { print(usage); System.exit(0); } int lines = 0; try { Class<?> c = Class.forName(args[0]); Method[] methods = c.getMethods(); Constructor[] ctors = c.getConstructors(); if (args.length == 1) { for (Method method : methods) print(p.matcher(method.toString()).replaceAll("")); for (Constructor ctor : ctors) print(p.matcher(ctor.toString()).replaceAll("")); lines = methods.length + ctors.length; } else { for (Method method : methods) if (method.toString().indexOf(args[1]) != -1) { print(p.matcher(method.toString()).replaceAll("")); lines++; } for (Constructor ctor : ctors) if (ctor.toString().indexOf(args[1]) != -1) { print(p.matcher(ctor.toString()).replaceAll("")); lines++; } } } catch (ClassNotFoundException e) { print("No such class: " + e); } }
public static void main(String[] args) { if (args.length == 0) { printDocs(); System.exit(0); } new IndexFastas(args); }
/** * The ActionListener implementation * * @param event the event. */ public void actionPerformed(ActionEvent event) { String searchText = textField.getText().trim(); if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) { textPane.setText("Blank search text is not allowed for large IdTables."); } else { File outputFile = null; if (saveAs.isSelected()) { outputFile = chooser.getSelectedFile(); if (outputFile != null) { String name = outputFile.getName(); int k = name.lastIndexOf("."); if (k != -1) name = name.substring(0, k); name += ".txt"; File parent = outputFile.getAbsoluteFile().getParentFile(); outputFile = new File(parent, name); chooser.setSelectedFile(outputFile); } if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0); outputFile = chooser.getSelectedFile(); } textPane.setText(""); Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile); searcher.start(); } }
public static void main(String[] args) throws Throwable { final ReentrantLock lock = new ReentrantLock(); lock.lock(); final ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock(); final ReentrantReadWriteLock.ReadLock readLock = rwlock.readLock(); final ReentrantReadWriteLock.WriteLock writeLock = rwlock.writeLock(); rwlock.writeLock().lock(); final BlockingQueue<Object> q = new LinkedBlockingQueue<Object>(); final Semaphore fairSem = new Semaphore(0, true); final Semaphore unfairSem = new Semaphore(0, false); // final int threads = // rnd.nextInt(Runtime.getRuntime().availableProcessors() + 1) + 1; final int threads = 3; // On Linux, this test runs very slowly for some reason, // so use a smaller number of iterations. // Solaris can handle 1 << 18. // On the other hand, jmap is much slower on Solaris... final int iterations = 1 << 8; final CyclicBarrier cb = new CyclicBarrier(threads + 1); for (int i = 0; i < threads; i++) new Thread() { public void run() { try { final Random rnd = new Random(); for (int j = 0; j < iterations; j++) { if (j == iterations / 10 || j == iterations - 1) { cb.await(); // Quiesce cb.await(); // Resume } // int t = rnd.nextInt(2000); int t = rnd.nextInt(900); check(!lock.tryLock(t, NANOSECONDS)); check(!readLock.tryLock(t, NANOSECONDS)); check(!writeLock.tryLock(t, NANOSECONDS)); equal(null, q.poll(t, NANOSECONDS)); check(!fairSem.tryAcquire(t, NANOSECONDS)); check(!unfairSem.tryAcquire(t, NANOSECONDS)); } } catch (Throwable t) { unexpected(t); } } }.start(); cb.await(); // Quiesce rendezvousChild(); // Measure cb.await(); // Resume cb.await(); // Quiesce rendezvousChild(); // Measure cb.await(); // Resume System.exit(failed); }
public static void main(String args[]) { // System.out.println( "Starting Jinan..." ); LineNumberReader in = null; BufferedWriter out = null; try { in = new LineNumberReader(new FileReader("Jinan.txt")); out = new BufferedWriter(new FileWriter("format.txt")); } catch (IOException e) { System.out.println(e); System.exit(-1); } String line; // 下面的表达式为:以K或没有K开头,接着是若干数字,然后是“路”字。 // 注意()表示group,以便提取其中的信息 Pattern p = Pattern.compile("^([Kk]?\\d+路).*$"); Matcher m; boolean flag = true; try { while (true) { line = in.readLine(); if (line == null) break; else if (line.equals("")) continue; m = p.matcher(line); if (flag != m.find()) // 这里必须先用find()触发匹配过程,才能开始使用 throw new RuntimeException("File format error: " + in.getLineNumber()); if (flag == true) { out.write(m.group(1)); // group(0) is the entire string, group(1) is the right one out.write(" "); flag = false; } else { out.write(line); out.newLine(); flag = true; } } in.close(); out.close(); } catch (IOException e) { System.out.println(e); System.exit(-1); } }
public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("Usage: java E17_JCommentExtractor file"); System.exit(0); } String src = TextFile.read(args[0]); Pattern p = Pattern.compile(CMNT_EXT_REGEX); Matcher m = p.matcher(src); while (m.find()) System.out.println(m.group(1) != null ? m.group(1) : m.group(2)); }
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { try { mainHelper(args); } catch (Daikon.TerminationMessage e) { System.err.println(e.getMessage()); System.exit(1); } // Any exception other than Daikon.TerminationMessage gets propagated. // This simplifies debugging by showing the stack trace. }
public static void main(String[] args) throws Exception { if (args.length < 3) { System.out.println("Usage: InferModel inputFile inferencerFile outputFile <topN>"); System.exit(0); } InferModel infermodel = new InferModel(); infermodel.parseArgs(args); // infermodel.test(); infermodel.doInference(); }
/** * Retrieve a default instance of ZCM using either the environment variable ZCM_DEFAULT_URL or the * default. If an exception occurs, System.exit(-1) is called. */ public static ZCM getSingleton() { if (singleton == null) { try { // XXX: add back in capability to use the ZCM_DEFAULT_URL env variable // as the default for getSingleton singleton = new ZCM(); } catch (Exception ex) { System.err.println("ZCM singleton fail: " + ex); System.exit(-1); return null; } } return singleton; }
void getTable() { if (chooser == null) { File userdir = new File(System.getProperty("user.dir")); chooser = new JFileChooser(userdir); } if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); fileLength = file.length(); setTitle(windowTitle + ": " + file.getAbsolutePath()); int size = Key.getEncryptionKeySize(this, true); key = Key.getEncryptionKey(this, true, size); if (key == null) key = defaultKey; initCipher(); } else System.exit(0); }
/** Prints out usage */ static void usage() { System.err.println( "Usage: hadoop com.tripadvisor.hadoop.BackupHdfs args\n" + " --hdfs-path path/on/hdfs\n" + " --local-path path/on/local/fs: path to hdfs backup\n" + " --preserve-path path/on/local/fs: path to preserve old files\n" + " [--no-preserve FILE]: list of file substrings to skip preserving\n" + " [--ignore-tables FILE]: list of tables to ignore\n" + " [--dry-run]: don't create any files on local fs\n" + " --date yesterday|last-day|last-week|UNIX-time-T\n" + " [--max-date UNIX-time-T]: don't backup any files newer than T\n" + " [--sleep N]: sleep N seconds after each file copy\n" + " [--max-bytes N]: don't back up more than N bytes\n"); System.exit(1); }
public static void main(String[] args) throws IOException { BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); if (args.length != 1) { System.err.println("Usage: MatchLines pattern"); System.exit(1); } Pattern patt = Pattern.compile(args[0]); Matcher matcher = patt.matcher(""); String line = null; while ((line = is.readLine()) != null) { matcher.reset(line); if (matcher.find()) { System.out.println("MATCH: " + line); } } }
public static void t1986main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder reg = new StringBuilder(); reg.append(in.readLine()); String sent; Pattern pattern = Pattern.compile(reg.toString()); Matcher matcher; while (in.ready()) { sent = in.readLine(); matcher = pattern.matcher(sent); if (matcher.find()) System.out.println("YES"); else System.out.println("NO"); } System.exit(0); }
public static void main(String[] args) throws Throwable { long startTime = System.nanoTime(); if (args.length < 2) { System.out.println("Not enough arguments"); System.exit(1); } String inputFileName = args[args.length - 2]; String outputFileName = args[args.length - 1]; includeNames.add(inputFileName); new File(cacheDirectoryName).mkdir(); BufferedWriter out = new BufferedWriter(new FileWriter(outputFileName)); mainContext = contextFromFilename(inputFileName); processFile(getBufferedReader(inputFileName, mainContext), out, mainContext); out.close(); System.out.println("Elapsed time: " + ((System.nanoTime() - startTime) / 1000000.0f) + " ms."); }
public static void main(String[] args) throws Exception { Properties configFile = new Properties(); configFile.load(new FileInputStream("my_config.properties")); myConnString = configFile.getProperty("MYCONN"); try { mysqlConn = DriverManager.getConnection(myConnString); myStm = mysqlConn.createStatement(); myStm.executeQuery("set wait_timeout = 7200"); } catch (Exception e) { System.out.println("MySQL Offline."); System.exit(1); } getBlogs(); Thread.sleep(1000); // For cleaning mongo cursos myStm.close(); }
public static void main(String[] args) { if (args.length < 2) { print("Usage:\njava TestRegularExpression " + "characterSequence regularExpression+"); System.exit(0); } print("Input: \"" + args[0] + "\""); for (String arg : args) { print("Regular expression: \"" + arg + "\""); Pattern p = Pattern.compile(arg); Matcher m = p.matcher(args[0]); if (!m.find()) print("No match found for " + "\"" + arg + "\""); m.reset(); while (m.find()) { print( "Match \"" + m.group() + "\" at position " + m.start() + ((m.end() - m.start() < 2) ? "" : ("-" + (m.end() - 1)))); } } }
/** This method will process each argument and assign new varibles */ public void processArgs(String[] args) { Pattern pat = Pattern.compile("-[a-z]"); for (int i = 0; i < args.length; i++) { String lcArg = args[i].toLowerCase(); Matcher mat = pat.matcher(lcArg); if (mat.matches()) { char test = args[i].charAt(1); try { switch (test) { case 'f': fastas = IO.extractFiles(args[i + 1], "fasta"); i++; break; case 'n': numberOfBases = Integer.parseInt(args[i + 1]); i++; break; case 'i': indexDirectory = new File(args[i + 1]); i++; break; case 'h': printDocs(); System.exit(0); default: Misc.printExit("\nError: unknown option! " + mat.group()); } } catch (Exception e) { Misc.printExit( "\nSorry, something doesn't look right with this parameter: -" + test + "\n"); } } } // make index directory? if (indexDirectory == null) { indexDirectory = new File(fastas[0].getParentFile(), "IndexedSequences"); indexDirectory.mkdir(); } }
private void setupChannelList() { channelPathList = new Vector(); if ((channelPathPattern != null) && !channelPathPattern.equals("")) appendChannelListFromPattern(); if ((channelPathListString != null) && !channelPathListString.equals("")) appendChannelListFromString(); Iterator channels = channelPathList.iterator(); if (!channels.hasNext()) { System.out.println("DataVideoGather: No data channels to monitor."); this.printUsage(); System.exit(0); } channelPathArray = new String[channelPathList.size()]; shortNameArray = new String[channelPathList.size()]; for (int i = 0; i < channelPathArray.length; i++) { ChannelTree.Node candidate = (ChannelTree.Node) channels.next(); channelPathArray[i] = candidate.getFullName(); shortNameArray[i] = candidate.getName(); } }
public String receiveMessage(BankMessage inputMessage) { String output = null; int opcode = inputMessage.opcode; int firstParam = inputMessage.parameters[0]; switch (opcode) { case CREATE: // SUCCESSFUL CREATE output = "You have created account " + firstParam; break; case 0x11: // INVALID INITIAL DEPOSIT output = "Error: Your deposit amount was not valid"; break; case 0x12: // ACCOUNT NUMBERS EXHAUSTED output = "Error: Unable to create account"; break; case DEPOSIT: case WITHDRAW: // SUCCESSFUL DEPOSIT OR WITHDRAW - RETURN BALANCE double balance = ((double) firstParam) / 100; output = String.format("Success: Your balance is now $%.2f", balance); break; case 0x21: case 0x31: case 0x41: case 0x51: // INVALID ACCOUNT NUMBER output = "Error: Your account number was not valid"; break; case 0x22: // INVALID DEPOSIT AMOUNT output = "Error: Your deposit amount was not valid"; break; case 0x32: // INVALID WITHDRAW AMOUNT output = "Error: Your withdrawal amount was not valid"; break; case GETBALANCE: // SUCCESSFUL BALANCE QUERY double bal = ((double) firstParam) / 100; output = String.format("Your balance is $%.2f", bal); break; case 0x42: // UNABLE TO GET BALANCE - MISC ERROR output = "Error: Unable to get balance"; break; case CLOSE: // SUCCESSFUL ACC CLOSE output = "Success: You closed account #" + firstParam; break; case 0x52: // UNABLE TO CLOSE - MISC ERROR output = "Error: Unable to close account #" + firstParam; break; default: System.out.println("We are sorry, the server is having difficulties."); System.exit(2); } return output; }
public static void main(String[] args) { // TODO main OptionParser parser = new OptionParser(); parser.acceptsAll(Arrays.asList("h", "help"), "Show this help dialog."); OptionSpec<String> serverOption = parser .acceptsAll(Arrays.asList("s", "server"), "Server to join.") .withRequiredArg() .describedAs("server-address[:port]"); OptionSpec<String> proxyOption = parser .acceptsAll( Arrays.asList("P", "proxy"), "SOCKS proxy to use. Ignored in presence of 'socks-proxy-list'.") .withRequiredArg() .describedAs("proxy-address"); OptionSpec<String> ownerOption = parser .acceptsAll( Arrays.asList("o", "owner"), "Owner of the bot (username of in-game control).") .withRequiredArg() .describedAs("username"); OptionSpec<?> offlineOption = parser.acceptsAll( Arrays.asList("O", "offline"), "Offline-mode. Ignores 'password' and 'account-list' (will " + "generate random usernames if 'username' is not supplied)."); OptionSpec<?> autoRejoinOption = parser.acceptsAll(Arrays.asList("a", "auto-rejoin"), "Auto-rejoin a server on disconnect."); OptionSpec<Integer> loginDelayOption = parser .acceptsAll( Arrays.asList("d", "login-delay"), "Delay between bot joins, in milliseconds. 5000 is " + "recommended if not using socks proxies.") .withRequiredArg() .describedAs("delay") .ofType(Integer.class); OptionSpec<Integer> botAmountOption = parser .acceptsAll( Arrays.asList("b", "bot-amount"), "Amount of bots to join. Must be <= amount of accounts.") .withRequiredArg() .describedAs("amount") .ofType(Integer.class); OptionSpec<String> protocolOption = parser .accepts( "protocol", "Protocol version to use. Can be either protocol number or Minecraft version.") .withRequiredArg(); OptionSpec<?> protocolsOption = parser.accepts("protocols", "List available protocols and exit."); OptionSpec<String> accountListOption = parser .accepts( "account-list", "File containing a list of accounts, in username/email:password format.") .withRequiredArg() .describedAs("file"); OptionSpec<String> socksProxyListOption = parser .accepts( "socks-proxy-list", "File containing a list of SOCKS proxies, in address:port format.") .withRequiredArg() .describedAs("file"); OptionSpec<String> httpProxyListOption = parser .accepts( "http-proxy-list", "File containing a list of HTTP proxies, in address:port format.") .withRequiredArg() .describedAs("file"); OptionSpec<String> captchaListOption = parser .accepts("captcha-list", "File containing a list of chat baised captcha to bypass.") .withRequiredArg() .describedAs("file"); OptionSet options; try { options = parser.parse(args); } catch (OptionException exception) { try { parser.printHelpOn(System.out); } catch (Exception exception1) { exception1.printStackTrace(); } return; } if (options.has("help")) { printHelp(parser); return; } if (options.has(protocolsOption)) { System.out.println("Available protocols:"); for (ProtocolProvider provider : ProtocolProvider.getProviders()) System.out.println( "\t" + provider.getMinecraftVersion() + " (" + provider.getSupportedVersion() + "): " + provider.getClass().getName()); System.out.println( "If no protocols are listed above, you may attempt to specify a protocol version in case the provider is actually in the class-path."); return; } final boolean offline = options.has(offlineOption); final boolean autoRejoin = options.has(autoRejoinOption); final List<String> accounts; if (options.has(accountListOption)) { accounts = loadAccounts(options.valueOf(accountListOption)); } else if (!offline) { System.out.println("Option 'accounts' must be supplied in " + "absence of option 'offline'."); printHelp(parser); return; } else accounts = null; final List<String> captcha; if (options.has(captchaListOption)) readCaptchaFile(options.valueOf(captchaListOption)); final String server; if (!options.has(serverOption)) { System.out.println("Option 'server' required."); printHelp(parser); return; } else server = options.valueOf(serverOption); final String owner; if (!options.has(ownerOption)) { System.out.println("Option 'owner' required."); printHelp(parser); return; } else owner = options.valueOf(ownerOption); final int protocol; if (options.has(protocolOption)) { String protocolString = options.valueOf(protocolOption); int parsedProtocol; try { parsedProtocol = Integer.parseInt(protocolString); } catch (NumberFormatException exception) { ProtocolProvider foundProvider = null; for (ProtocolProvider provider : ProtocolProvider.getProviders()) if (protocolString.equals(provider.getMinecraftVersion())) foundProvider = provider; if (foundProvider == null) { System.out.println("No provider found for Minecraft version '" + protocolString + "'."); return; } else parsedProtocol = foundProvider.getSupportedVersion(); } protocol = parsedProtocol; } else protocol = MinecraftBot.LATEST_PROTOCOL; final List<String> socksProxies; if (options.has(socksProxyListOption)) socksProxies = loadProxies(options.valueOf(socksProxyListOption)); else socksProxies = null; final boolean useProxy = socksProxies != null; final List<String> httpProxies; if (options.has(httpProxyListOption)) httpProxies = loadLoginProxies(options.valueOf(httpProxyListOption)); else if (!offline && accounts != null) { System.out.println( "Option 'http-proxy-list' required if " + "option 'account-list' is supplied."); printHelp(parser); return; } else httpProxies = null; final int loginDelay; if (options.has(loginDelayOption)) loginDelay = options.valueOf(loginDelayOption); else loginDelay = 0; final int botAmount; if (!options.has(botAmountOption)) { System.out.println("Option 'bot-amount' required."); printHelp(parser); return; } else botAmount = options.valueOf(botAmountOption); initGui(); while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } final Queue<Runnable> lockQueue = new ArrayDeque<Runnable>(); ExecutorService service = Executors.newFixedThreadPool(botAmount + (loginDelay > 0 ? 1 : 0)); final Object firstWait = new Object(); if (loginDelay > 0) { service.execute( new Runnable() { @Override public void run() { synchronized (firstWait) { try { firstWait.wait(); } catch (InterruptedException exception) { } } while (true) { try { Thread.sleep(loginDelay); } catch (InterruptedException exception) { } synchronized (lockQueue) { if (lockQueue.size() > 0) { Runnable thread = lockQueue.poll(); synchronized (thread) { thread.notifyAll(); } lockQueue.offer(thread); } else continue; } while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } } } }); } final List<String> accountsInUse = new ArrayList<String>(); final Map<String, AtomicInteger> workingProxies = new HashMap<String, AtomicInteger>(); for (int i = 0; i < botAmount; i++) { final int botNumber = i; Runnable runnable = new Runnable() { @Override public void run() { if (loginDelay > 0) synchronized (lockQueue) { lockQueue.add(this); } Random random = new Random(); if (!offline) { AuthService authService = new LegacyAuthService(); boolean authenticated = false; user: while (true) { if (authenticated) { authenticated = false; sessionCount.decrementAndGet(); } Session session = null; String loginProxy; String account = accounts.get(random.nextInt(accounts.size())); synchronized (accountsInUse) { if (accountsInUse.size() == accounts.size()) System.exit(0); while (accountsInUse.contains(account)) account = accounts.get(random.nextInt(accounts.size())); accountsInUse.add(account); } String[] accountParts = account.split(":"); while (true) { while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } synchronized (workingProxies) { Iterator<String> iterator = workingProxies.keySet().iterator(); if (iterator.hasNext()) loginProxy = iterator.next(); else loginProxy = httpProxies.get(random.nextInt(httpProxies.size())); ; } try { session = authService.login( accountParts[0], accountParts[1], toProxy(loginProxy, Proxy.Type.HTTP)); // addAccount(session); synchronized (workingProxies) { AtomicInteger count = workingProxies.get(loginProxy); if (count != null) count.set(0); else workingProxies.put(loginProxy, new AtomicInteger()); } sessionCount.incrementAndGet(); authenticated = true; break; } catch (IOException exception) { synchronized (workingProxies) { workingProxies.remove(loginProxy); } System.err.println("[Bot" + botNumber + "] " + loginProxy + ": " + exception); } catch (AuthenticationException exception) { if (exception.getMessage().contains("Too many failed logins")) { synchronized (workingProxies) { AtomicInteger count = workingProxies.get(loginProxy); if (count != null && count.incrementAndGet() >= 5) workingProxies.remove(loginProxy); } } System.err.println("[Bot" + botNumber + "] " + loginProxy + ": " + exception); continue user; } } System.out.println("[" + session.getUsername() + "] " + session); while (!joins.get()) { synchronized (joins) { try { joins.wait(5000); } catch (InterruptedException exception) { } } } if (loginDelay > 0) { synchronized (this) { try { synchronized (firstWait) { firstWait.notifyAll(); } wait(); } catch (InterruptedException exception) { } } } while (true) { String proxy = useProxy ? socksProxies.get(random.nextInt(socksProxies.size())) : null; try { DarkBotMCSpambot bot = new DarkBotMCSpambot( generateData( server, session.getUsername(), session.getPassword(), authService, session, protocol, null, proxy), owner); while (bot.getBot().isConnected()) { try { Thread.sleep(500); } catch (InterruptedException exception) { exception.printStackTrace(); } } if (!autoRejoin) break; } catch (Exception exception) { exception.printStackTrace(); System.out.println( "[" + session.getUsername() + "] Error connecting: " + exception.getCause().toString()); } } System.out.println("[" + session.getUsername() + "] Account failed"); } } else { while (true) { String proxy = useProxy ? socksProxies.get(random.nextInt(socksProxies.size())) : null; try { String username; if (accounts != null) { username = accounts.get(random.nextInt(accounts.size())).split(":")[0]; synchronized (accountsInUse) { while (accountsInUse.contains(username)) username = accounts.get(random.nextInt(accounts.size())); accountsInUse.add(username); } } else username = Util.generateRandomString(10 + random.nextInt(6)); if (loginDelay > 0) { synchronized (this) { try { synchronized (firstWait) { firstWait.notifyAll(); } wait(); } catch (InterruptedException exception) { } } } DarkBotMCSpambot bot = new DarkBotMCSpambot( generateData(server, username, null, null, null, protocol, null, proxy), owner); while (bot.getBot().isConnected()) { try { Thread.sleep(500); } catch (InterruptedException exception) { exception.printStackTrace(); } } if (!autoRejoin) break; else continue; } catch (Exception exception) { System.out.println( "[Bot" + botNumber + "] Error connecting: " + exception.toString()); } } } } }; service.execute(runnable); } service.shutdown(); while (!service.isTerminated()) { try { service.awaitTermination(9000, TimeUnit.DAYS); } catch (InterruptedException exception) { exception.printStackTrace(); } } System.exit(0); }
public static void main(String[] args) { // TODO main OptionParser parser = new OptionParser(); parser.acceptsAll(Arrays.asList("h", "help"), "Show this help dialog."); OptionSpec<String> serverOption = parser .acceptsAll(Arrays.asList("s", "server"), "Server to join.") .withRequiredArg() .describedAs("server-address[:port]"); OptionSpec<String> proxyOption = parser .acceptsAll( Arrays.asList("P", "proxy"), "SOCKS proxy to use. Ignored in presence of 'socks-proxy-list'.") .withRequiredArg() .describedAs("proxy-address"); OptionSpec<String> ownerOption = parser .acceptsAll( Arrays.asList("o", "owner"), "Owner of the bot (username of in-game control).") .withRequiredArg() .describedAs("username"); OptionSpec<?> offlineOption = parser.acceptsAll( Arrays.asList("O", "offline"), "Offline-mode. Ignores 'password' and 'account-list' (will " + "generate random usernames if 'username' is not supplied)."); OptionSpec<?> autoRejoinOption = parser.acceptsAll(Arrays.asList("a", "auto-rejoin"), "Auto-rejoin a server on disconnect."); OptionSpec<Integer> loginDelayOption = parser .acceptsAll( Arrays.asList("d", "login-delay"), "Delay between bot joins, in milliseconds. 5000 is " + "recommended if not using socks proxies.") .withRequiredArg() .describedAs("delay") .ofType(Integer.class); OptionSpec<Integer> botAmountOption = parser .acceptsAll( Arrays.asList("b", "bot-amount"), "Amount of bots to join. Must be <= amount of accounts.") .withRequiredArg() .describedAs("amount") .ofType(Integer.class); OptionSpec<String> accountListOption = parser .accepts( "account-list", "File containing a list of accounts, in username/email:password format.") .withRequiredArg() .describedAs("file"); OptionSpec<String> socksProxyListOption = parser .accepts( "socks-proxy-list", "File containing a list of SOCKS proxies, in address:port format.") .withRequiredArg() .describedAs("file"); OptionSpec<String> httpProxyListOption = parser .accepts( "http-proxy-list", "File containing a list of HTTP proxies, in address:port format.") .withRequiredArg() .describedAs("file"); OptionSet options; try { options = parser.parse(args); } catch (OptionException exception) { try { parser.printHelpOn(System.out); } catch (Exception exception1) { exception1.printStackTrace(); } return; } if (options.has("help")) { printHelp(parser); return; } final boolean offline = options.has(offlineOption); final boolean autoRejoin = options.has(autoRejoinOption); final List<String> accounts; if (options.has(accountListOption)) { accounts = loadAccounts(options.valueOf(accountListOption)); } else if (!offline) { System.out.println("Option 'accounts' must be supplied in " + "absence of option 'offline'."); printHelp(parser); return; } else accounts = null; final String server; if (!options.has(serverOption)) { System.out.println("Option 'server' required."); printHelp(parser); return; } else server = options.valueOf(serverOption); final String owner; if (!options.has(ownerOption)) { System.out.println("Option 'owner' required."); printHelp(parser); return; } else owner = options.valueOf(ownerOption); final List<String> socksProxies; if (options.has(socksProxyListOption)) socksProxies = loadProxies(options.valueOf(socksProxyListOption)); else socksProxies = null; final boolean useProxy = socksProxies != null; final List<String> httpProxies; if (options.has(httpProxyListOption)) httpProxies = loadLoginProxies(options.valueOf(httpProxyListOption)); else if (!offline && accounts != null) { System.out.println( "Option 'http-proxy-list' required if " + "option 'account-list' is supplied."); printHelp(parser); return; } else httpProxies = null; final int loginDelay; if (options.has(loginDelayOption)) loginDelay = options.valueOf(loginDelayOption); else loginDelay = 0; final int botAmount; if (!options.has(botAmountOption)) { System.out.println("Option 'bot-amount' required."); printHelp(parser); return; } else botAmount = options.valueOf(botAmountOption); initGui(); while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } final Queue<Runnable> lockQueue = new ArrayDeque<Runnable>(); ExecutorService service = Executors.newFixedThreadPool(botAmount + (loginDelay > 0 ? 1 : 0)); final Object firstWait = new Object(); if (loginDelay > 0) { service.execute( new Runnable() { @Override public void run() { synchronized (firstWait) { try { firstWait.wait(); } catch (InterruptedException exception) { } } while (true) { if (die) return; while (slotsTaken.get() >= 2) { synchronized (slotsTaken) { try { slotsTaken.wait(500); } catch (InterruptedException exception) { } } } synchronized (lockQueue) { if (lockQueue.size() > 0) { Runnable thread = lockQueue.poll(); synchronized (thread) { thread.notifyAll(); } lockQueue.offer(thread); } else continue; } try { Thread.sleep(loginDelay); } catch (InterruptedException exception) { } while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } } } }); } final List<String> accountsInUse = new ArrayList<String>(); for (int i = 0; i < botAmount; i++) { final int botNumber = i; Runnable runnable = new Runnable() { @Override public void run() { if (loginDelay > 0) synchronized (lockQueue) { lockQueue.add(this); } Random random = new Random(); if (!offline) { boolean authenticated = false; user: while (true) { if (authenticated) { authenticated = false; sessionCount.decrementAndGet(); } Session session = null; String loginProxy; String account = accounts.get(random.nextInt(accounts.size())); synchronized (accountsInUse) { if (accountsInUse.size() == accounts.size()) System.exit(0); while (accountsInUse.contains(account)) account = accounts.get(random.nextInt(accounts.size())); accountsInUse.add(account); } String[] accountParts = account.split(":"); while (true) { while (!sessions.get()) { synchronized (sessions) { try { sessions.wait(5000); } catch (InterruptedException exception) { } } } loginProxy = httpProxies.get(random.nextInt(httpProxies.size())); try { session = Util.retrieveSession(accountParts[0], accountParts[1], loginProxy); // addAccount(session); sessionCount.incrementAndGet(); authenticated = true; break; } catch (AuthenticationException exception) { System.err.println("[Bot" + botNumber + "] " + exception); if (!exception.getMessage().startsWith("Exception")) // && !exception.getMessage().equals( // "Too many failed logins")) continue user; } } System.out.println( "[" + session.getUsername() + "] Password: "******", Session ID: " + session.getSessionId()); while (!joins.get()) { synchronized (joins) { try { joins.wait(5000); } catch (InterruptedException exception) { } } } if (loginDelay > 0) { synchronized (this) { try { synchronized (firstWait) { firstWait.notifyAll(); } wait(); } catch (InterruptedException exception) { } } } while (true) { String proxy = useProxy ? socksProxies.get(random.nextInt(socksProxies.size())) : null; try { new DarkBotMCSpambot( DARK_BOT, server, session.getUsername(), session.getPassword(), session.getSessionId(), null, proxy, owner); if (die) break user; else if (!autoRejoin) break; } catch (Exception exception) { exception.printStackTrace(); System.out.println( "[" + session.getUsername() + "] Error connecting: " + exception.getCause().toString()); } } System.out.println("[" + session.getUsername() + "] Account failed"); } } else { while (true) { String proxy = useProxy ? socksProxies.get(random.nextInt(socksProxies.size())) : null; try { String username = ""; if (accounts != null) { username = accounts.get(random.nextInt(accounts.size())).split(":")[0]; synchronized (accountsInUse) { while (accountsInUse.contains(username)) username = accounts.get(random.nextInt(accounts.size())); accountsInUse.add(username); } } else for (int i = 0; i < 10 + random.nextInt(6); i++) username += alphas[random.nextInt(alphas.length)]; if (loginDelay > 0) { synchronized (this) { try { synchronized (firstWait) { firstWait.notifyAll(); } wait(); } catch (InterruptedException exception) { } } } new DarkBotMCSpambot(DARK_BOT, server, username, "", "", null, proxy, owner); if (die || !autoRejoin) break; else continue; } catch (Exception exception) { System.out.println( "[Bot" + botNumber + "] Error connecting: " + exception.toString()); } } } } }; service.execute(runnable); } service.shutdown(); while (!service.isTerminated()) { try { service.awaitTermination(9000, TimeUnit.DAYS); } catch (InterruptedException exception) { exception.printStackTrace(); } } System.exit(0); }
/** * Method to move files from HDFS to local filesystem * * <p>localPath: Path on the machines filesystem fs:FileSystem object from HDFS pathList:List of * paths for files that might need to be backed up size:max size in bytes to be backed up * * <p>ReturnsDate of the last files backed up if reached size limit, else, zero */ public long backupFiles( String localPath, String preservePath, FileSystem fs, ArrayList<Path> pathList, long size) { Path fsPath; long tmpSize = 0; long tmpDate = 0; // Start iterating over all paths for (Path hdfsPath : pathList) { try { long nFileSize = fs.getContentSummary(hdfsPath).getLength(); tmpSize = tmpSize + nFileSize; if ((tmpSize <= size) || (size == 0)) { FileStatus stat = fs.getFileStatus(hdfsPath); System.err.println( "File " + hdfsPath.toUri().getPath() + " " + nFileSize + " bytes, " + "perms: " + stat.getOwner() + "/" + stat.getGroup() + ", " + stat.getPermission().toString()); tmpDate = stat.getModificationTime() / 1000; String sFsPath = localPath + hdfsPath.toUri().getPath(); fsPath = new Path(sFsPath); File f = new File(sFsPath); // COMMENTED OUT: until a few backup cycles run // and the mtime gets in fact set on all copied // files. // // ignore it if the file exists and has the same mtime // if (f.exists() && f.isFile() && f.lastModified() == stat.getModificationTime()) // { // System.out.println("no need to backup " + f.toString() + ", mtime matches hdfs"); // continue; // } if (false == m_bDryRun) { // check if we need to back up the local file // (not directory), if it already exists. if (f.exists() && f.isFile()) { // ignore files with substrings in the // no-preserve file if (true == doPreserveFile(sFsPath)) { // move it to the backup path String sNewPath = preservePath + hdfsPath.toUri().getPath(); File newFile = new File(sNewPath); // create directory structure for new file? if (false == newFile.getParentFile().exists()) { if (false == newFile.getParentFile().mkdirs()) { System.err.println("Failed to mkdirs " + newFile.getParentFile().toString()); System.exit(1); } } // rename existing file to new location if (false == f.renameTo(newFile)) { System.err.println( "Failed to renameTo " + f.toString() + " to " + newFile.toString()); System.exit(1); } System.out.println("preserved " + f.toString() + " into " + newFile.toString()); } else { System.out.println("skipped preservation of " + f.toString()); } } // copy from hdfs to local filesystem fs.copyToLocalFile(hdfsPath, fsPath); // set the mtime to match hdfs file f.setLastModified(stat.getModificationTime()); // compare checksums on both files compareChecksums(fs, hdfsPath, sFsPath); } // don't print the progress after every file -- go // by at least 1% increments long nPercentDone = (long) (100 * tmpSize / m_nTotalBytes); if (nPercentDone > m_nLastPercentBytesDone) { System.out.println( "progress: copied " + prettyPrintBytes(tmpSize) + ", " + nPercentDone + "% done" + ", tstamp=" + tmpDate); m_nLastPercentBytesDone = nPercentDone; } if (m_nSleepSeconds > 0) { try { Thread.sleep(1000 * m_nSleepSeconds); } catch (Exception e2) { // ignore } } } else { return tmpDate; } } catch (IOException e) { System.err.println("FATAL ERROR: Something wrong with the file"); System.err.println(e); System.out.println(tmpDate); System.exit(1); return 0; } } return 0; }
/** This method will process each argument and assign new variables */ public void processArgs(String[] args) { Pattern pat = Pattern.compile("-[a-z]"); System.out.println( "\n" + IO.fetchUSeqVersion() + " Arguments: " + Misc.stringArrayToString(args, " ") + "\n"); for (int i = 0; i < args.length; i++) { String lcArg = args[i].toLowerCase(); Matcher mat = pat.matcher(lcArg); if (mat.matches()) { char test = args[i].charAt(1); try { switch (test) { case 'o': jobId = args[++i]; break; case 's': sampleId = args[++i]; break; case 'm': submitter = args[++i]; break; case 'y': analysisType = args[++i]; break; case 'w': webRootForLinks = new File(args[++i]); break; case 'e': snpEffGenome = args[++i]; break; case 'i': minimumReadDepth = args[++i]; break; case 't': threads = args[++i]; break; case 'l': uploadVarsToNGSWeb = true; break; case 'j': pJar = new File(args[++i]); break; case 'p': truncPipePropFile = new File(args[++i]); break; case 'q': bedForCoverageQC = new File(args[++i]); break; case 'b': bedForVarCalling = new File(args[++i]); break; case 'r': fastaReference = new File(args[++i]); break; case 'u': unfilteredBam = new File(args[++i]); break; case 'f': finalBam = new File(args[++i]); break; case 'v': finalVcf = new File(args[++i]); break; case 'd': outputDirectory = new File(args[++i]); break; case 'c': referenceDir = new File(args[++i]); break; case 'h': printDocs(); System.exit(0); default: Misc.printErrAndExit("\nProblem, unknown option! " + mat.group()); } } catch (Exception e) { Misc.printErrAndExit( "\nSorry, something doesn't look right with this parameter: -" + test + "\n"); } } } // check output dir and if needed set sampleId if (outputDirectory != null) { outputDirectory.mkdirs(); if (sampleId.length() == 0) sampleId = outputDirectory.getName(); } // check root directory if needed if (webRootForLinks != null) { if (webRootForLinks.exists() == false) webRootForLinks.mkdirs(); // links dir? File links = new File(webRootForLinks, "links"); if (links.exists() == false) links.mkdirs(); } // look for required fields and files checkPrintFields(); checkPrintFiles(); checkForGzippedVcf(); }
public BankMessage makeMessage() { Scanner stdIn = new Scanner(System.in); int userInput; int[] opcodes = {CREATE, DEPOSIT, WITHDRAW, GETBALANCE, CLOSE}; do { userInput = stdIn.nextInt(); } while (!(userInput >= 1 && userInput <= 5)); int opcode = opcodes[userInput - 1]; int[] parameters = new int[2]; // create a pattern only accepting positive numbers with at most 2 decimal places Pattern dollar = Pattern.compile( "^\\$?([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$"); String input = null; // populate parameters list switch (opcode) { case CREATE: do { System.out.println("How much for initial deposit?"); input = stdIn.next(); } while ((dollar.matcher(input).matches()) == false); parameters[0] = (int) (Double.parseDouble(input) * 100); break; case DEPOSIT: System.out.println("Which account?"); parameters[0] = stdIn.nextInt(); do { System.out.println("How much to deposit?"); input = stdIn.next(); } while ((dollar.matcher(input).matches()) == false); parameters[1] = (int) (Double.parseDouble(input) * 100); break; case WITHDRAW: System.out.println("Which account?"); parameters[0] = stdIn.nextInt(); do { System.out.println("How much to withdraw?"); input = stdIn.next(); } while ((dollar.matcher(input).matches()) == false); parameters[1] = (int) (Double.parseDouble(input) * 100); break; case GETBALANCE: System.out.println("Which account?"); parameters[0] = stdIn.nextInt(); break; case CLOSE: System.out.println("Which account?"); parameters[0] = stdIn.nextInt(); break; default: System.out.println("Invalid opcode. System failure."); System.exit(-1); } BankMessage output = buildMessage(opcode, parameters); return output; }
private void systemexit() { System.out.println("DocumentEdit Close."); System.exit(0); // 0表示正常關閉 }