List of usage examples for java.lang System console
public static Console console()
From source file:javadocofflinesearch.tools.Commandline.java
@Override public Formatter createFormatter(PrintStream out) { if (isPlain()) { return new PlainTextFormatter(out, this.getSetup()); } else if (isColoured()) { return new ColoredPlainTextFormatter(out, this.getSetup()); } else if (isHtml()) { return new StaticHtmlFormatter(out, this.getSetup()); } else if (isAjax()) { return new AjaxHtmlFormatter(out, this.getSetup()); } else {/*from ww w . j av a 2 s . c o m*/ if (System.console() == null || isWindows()) { return new PlainTextFormatter(out, this.getSetup()); } else { return new ColoredPlainTextFormatter(out, this.getSetup()); } } }
From source file:org.dataconservancy.packaging.tool.cli.PackageGenerationApp.java
private File getOutputFile(PackageGenerationParameters params, Package pkg) { String name = pkg.getPackageName(); String loc = params.getParam(GeneralParameterNames.PACKAGE_LOCATION, 0); File outfile = new File(loc, name); if (outfile.exists() && !overwriteIfExists) { Console c = System.console(); String answer = ""; if (c != null) { answer = c.readLine("File %s exists. Do you wish to overwrite? (y/N) ", outfile); }//from w w w .j a va 2s . com // if they don't want to overwrite the output, find a file to write to by appending // a number to it if (answer.isEmpty() || !answer.toLowerCase().startsWith("y")) { int lastDot = name.lastIndexOf("."); int secondDot = name.lastIndexOf(".", lastDot - 1); String namePart; String extPart; if (secondDot != -1 && lastDot - secondDot <= 4) { namePart = name.substring(0, secondDot); extPart = name.substring(secondDot); } else { namePart = name.substring(0, lastDot); extPart = name.substring(lastDot); } int i = 1; do { outfile = new File(loc, namePart + "(" + i + ")" + extPart); i += 1; } while (outfile.exists()); } } return outfile; }
From source file:chatbot.Chatbot.java
/** ************************************************************************************************** * Run with a given file//w w w. jav a 2 s. c o m */ private static void run(String fname) throws IOException { List<String> documents = null; try { if (asResource) documents = TextFileUtil.readLines(fname, false); //documents = TextFileUtil.readFile(fname, false); } catch (IOException e) { System.out.println("Couldn't read document: " + fname + ". Exiting"); return; } Chatbot cb; ResourceBundle resourceBundle = ResourceBundle.getBundle("corpora"); if (asResource) cb = new Chatbot(documents, resourceBundle.getString("stopWordsDirectoryName")); else { cb = new Chatbot(resourceBundle.getString("stopWordsDirectoryName")); cb.readFile(fname); } System.out.println("Hi, I'm Cloudio, tell/ask me something. Type 'quit' to exit"); if (isDevelopment) { Scanner scanner = new Scanner(System.in); while (true) { System.out.print("User: "); String input = scanner.nextLine(); if (input.toLowerCase().trim().equals("quit")) break; System.out.print("Cloudio: "); System.out.println(cb.matchBestInput(input)); } } else { while (true) { Console c = System.console(); if (c == null) { System.err.println("No console."); System.exit(1); } String input = c.readLine("> "); if (input.toLowerCase().trim().equals("quit")) System.exit(1); System.out.println("Cloudio:" + cb.matchBestInput(input)); } } }
From source file:hudson.Functions.java
/** * Are we running on JRE6 or above?/* w w w. j a v a 2 s . c om*/ */ @IgnoreJRERequirement public static boolean isMustangOrAbove() { try { System.console(); return true; } catch (LinkageError e) { return false; } }
From source file:com.trsst.Command.java
public int doPost(Client client, CommandLine commands, LinkedList<String> arguments, PrintStream out, InputStream in) {/*from w w w.jav a2 s.c om*/ String id = null; if (arguments.size() == 0 && commands.getArgList().size() == 0) { printPostUsage(); return 127; // "command not found" } if (arguments.size() > 0) { id = arguments.removeFirst(); System.err.println("Obtaining keys for feed id: " + id); } else { System.err.println("Generating new feed id... "); } // read input text String subject = commands.getOptionValue("s"); String verb = commands.getOptionValue("v"); String base = commands.getOptionValue("b"); String body = commands.getOptionValue("c"); String name = commands.getOptionValue("n"); String email = commands.getOptionValue("m"); String uri = commands.getOptionValue("uri"); String title = commands.getOptionValue("t"); String subtitle = commands.getOptionValue("subtitle"); String icon = commands.getOptionValue("i"); if (icon == null && commands.hasOption("i")) { icon = "-"; } String logo = commands.getOptionValue("l"); if (logo == null && commands.hasOption("l")) { logo = "-"; } String attach = commands.getOptionValue("a"); if (attach == null && commands.hasOption("a")) { attach = "-"; } String[] recipients = commands.getOptionValues("e"); String[] mentions = commands.getOptionValues("r"); String[] tags = commands.getOptionValues("g"); String url = commands.getOptionValue("u"); String vanity = commands.getOptionValue("vanity"); // obtain password char[] password = null; String pass = commands.getOptionValue("p"); if (pass != null) { password = pass.toCharArray(); } else { try { Console console = System.console(); if (console != null) { password = console.readPassword("Password: "); } else { log.info("No console detected for password input."); } } catch (Throwable t) { log.error("Unexpected error while reading password", t); } } if (password == null) { log.error("Password is required to post."); return 127; // "command not found" } if (password.length < 6) { System.err.println("Password must be at least six characters in length."); return 127; // "command not found" } // obtain keys KeyPair signingKeys = null; KeyPair encryptionKeys = null; String keyPath = commands.getOptionValue("k"); // if id was not specified from the command line if (id == null) { // if password was not specified from command line if (pass == null) { try { // verify password char[] verify = null; Console console = System.console(); if (console != null) { verify = console.readPassword("Re-type Password: "); } else { log.info("No console detected for password verification."); } if (verify == null || verify.length != password.length) { System.err.println("Passwords do not match."); return 127; // "command not found" } for (int i = 0; i < verify.length; i++) { if (verify[i] != password[i]) { System.err.println("Passwords do not match."); return 127; // "command not found" } verify[i] = 0; } } catch (Throwable t) { log.error("Unexpected error while verifying password: " + t.getMessage(), t); } } // create new account if (base == null) { // default to trsst hub base = "https://home.trsst.com/feed"; } // generate vanity id if required if (vanity != null) { System.err.println("Searching for vanity feed id prefix: " + vanity); switch (vanity.length()) { case 0: case 1: break; case 2: System.err.println("This may take several minutes."); break; case 3: System.err.println("This may take several hours."); break; case 4: System.err.println("This may take several days."); break; case 5: System.err.println("This may take several months."); break; default: System.err.println("This may take several years."); break; } System.err.println("Started: " + new Date()); System.err.println("^C to exit"); } do { signingKeys = Common.generateSigningKeyPair(); id = Common.toFeedId(signingKeys.getPublic()); } while (vanity != null && !id.startsWith(vanity)); if (vanity != null) { System.err.println("Finished: " + new Date()); } encryptionKeys = Common.generateEncryptionKeyPair(); System.err.println("New feed id created: " + id); File keyFile; if (keyPath != null) { keyFile = new File(keyPath, id + Common.KEY_EXTENSION); } else { keyFile = new File(Common.getClientRoot(), id + Common.KEY_EXTENSION); } // persist to keystore writeSigningKeyPair(signingKeys, id, keyFile, password); writeEncryptionKeyPair(encryptionKeys, id, keyFile, password); } else { File keyFile; if (keyPath != null) { keyFile = new File(Common.getClientRoot(), keyPath); } else { keyFile = new File(Common.getClientRoot(), id + Common.KEY_EXTENSION); } if (keyFile.exists()) { System.err.println("Using existing account id: " + id); } else { System.err.println("Cannot locate keys for account id: " + id); return 78; // "configuration error" } signingKeys = readSigningKeyPair(id, keyFile, password); if (signingKeys != null) { encryptionKeys = readEncryptionKeyPair(id, keyFile, password); if (encryptionKeys == null) { encryptionKeys = signingKeys; } } } // clear password chars for (int i = 0; i < password.length; i++) { password[i] = 0; } if (signingKeys == null) { System.err.println("Could not obtain keys for signing."); return 73; // "can't create output error" } String[] recipientIds = null; if (recipients != null) { LinkedList<String> keys = new LinkedList<String>(); for (int i = 0; i < recipients.length; i++) { if ("-".equals(recipients[i])) { // "-" is shorthand for encrypt for mentioned ids if (mentions != null) { for (String mention : mentions) { if (Common.isFeedId(mention)) { keys.add(mention); } } } } else if (Common.isFeedId(recipients[i])) { keys.add(recipients[i]); } else { log.warn("Could not parse recipient id: " + recipients[i]); } } recipientIds = keys.toArray(new String[0]); } // handle binary attachment String mimetype = null; byte[] attachment = null; if (attach != null) { InputStream input = null; try { if ("-".equals(attach)) { input = new BufferedInputStream(in); } else { File file = new File(attach); input = new BufferedInputStream(new FileInputStream(file)); System.err.println("Attaching: " + file.getCanonicalPath()); } attachment = Common.readFully(input); mimetype = new Tika().detect(attachment); System.err.println("Detected type: " + mimetype); } catch (Throwable t) { log.error("Could not read attachment: " + attach, t); return 73; // "can't create output error" } finally { try { input.close(); } catch (IOException ioe) { // suppress any futher error on closing } } } Object result; try { EntryOptions options = new EntryOptions(); options.setStatus(subject); options.setVerb(verb); if (mentions != null) { options.setMentions(mentions); } if (tags != null) { options.setTags(tags); } options.setBody(body); if (attachment != null) { options.addContentData(attachment, mimetype); } else if (url != null) { options.setContentUrl(url); } FeedOptions feedOptions = new FeedOptions(); feedOptions.setAuthorEmail(email); feedOptions.setAuthorName(name); feedOptions.setAuthorUri(uri); feedOptions.setTitle(title); feedOptions.setSubtitle(subtitle); feedOptions.setBase(base); if (icon != null) { if ("-".equals(icon)) { feedOptions.setAsIcon(true); } else { feedOptions.setIconURL(icon); } } if (logo != null) { if ("-".equals(logo)) { feedOptions.setAsLogo(true); } else { feedOptions.setLogoURL(logo); } } if (recipientIds != null) { EntryOptions publicEntry = new EntryOptions().setStatus("Encrypted content").setVerb("encrypt"); // TODO: add duplicate mentions to outside of envelope options.encryptFor(recipientIds, publicEntry); } result = client.post(signingKeys, encryptionKeys, options, feedOptions); } catch (IllegalArgumentException e) { log.error("Invalid request: " + id + " : " + e.getMessage(), e); return 76; // "remote error" } catch (IOException e) { log.error("Error connecting to service for id: " + id, e); return 76; // "remote error" } catch (org.apache.abdera.security.SecurityException e) { log.error("Error generating signatures for id: " + id, e); return 73; // "can't create output error" } catch (Exception e) { log.error("General security error for id: " + id, e); return 74; // "general io error" } if (result != null) { if (format) { out.println(Common.formatXML(result.toString())); } else { out.println(result.toString()); } } return 0; // "OK" }
From source file:org.apache.maven.cli.MavenCli.java
private void encryption(CliRequest cliRequest) throws Exception { if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_MASTER_PASSWORD); if (passwd == null) { Console cons = System.console(); char[] password = (cons == null) ? null : cons.readPassword("Master password: "); if (password != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); }//from w w w . j a va2 s . com } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); System.out .println(cipher.encryptAndDecorate(passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION)); throw new ExitException(0); } else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_PASSWORD); if (passwd == null) { Console cons = System.console(); char[] password = (cons == null) ? null : cons.readPassword("Password: "); if (password != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); } } String configurationFile = dispatcher.getConfigurationFile(); if (configurationFile.startsWith("~")) { configurationFile = System.getProperty("user.home") + configurationFile.substring(1); } String file = System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile); String master = null; SettingsSecurity sec = SecUtil.read(file, true); if (sec != null) { master = sec.getMaster(); } if (master == null) { throw new IllegalStateException("Master password is not set in the setting security file: " + file); } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); String masterPasswd = cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION); System.out.println(cipher.encryptAndDecorate(passwd, masterPasswd)); throw new ExitException(0); } }
From source file:org.apache.cxf.cwiki.SiteExporter.java
private static synchronized void doLogin() throws Exception { if (loginToken == null) { Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:login"); Element el2 = doc.createElement("in0"); if (userName == null) { System.out.println("Enter username: "); el2.setTextContent(System.console().readLine()); } else {//from w w w. j a va 2s . co m el2.setTextContent(userName); } el.appendChild(el2); el2 = doc.createElement("in1"); el.appendChild(el2); if (password == null) { System.out.println("Enter password: "); el2.setTextContent(new String(System.console().readPassword())); } else { el2.setTextContent(password); } doc.appendChild(el); doc = getDispatch().invoke(doc); loginToken = doc.getDocumentElement().getFirstChild().getTextContent(); } }
From source file:me.gloriouseggroll.quorrabot.Quorrabot.java
@Subscribe public void onConsoleMessage(ConsoleInputEvent msg) { String message = msg.getMsg(); boolean changed = false; if (message == null) { return;/*from w w w . j a va 2s.c om*/ } if (message.equals("debugon")) { Quorrabot.setDebugging(true); } //used for testing notifications if (message.equalsIgnoreCase("subtest")) { String randomUser = generateRandomString(10); EventBus.instance().post( new IrcPrivateMessageEvent(this.session, "twitchnotify", randomUser + " just subscribed!")); } if (message.equalsIgnoreCase("resubtest")) { String randomUser = generateRandomString(10); EventBus.instance().post(new IrcPrivateMessageEvent(this.session, "twitchnotify", randomUser + " just subscribed for 10 months in a row!")); } if (message.equalsIgnoreCase("followtest")) { String randomUser = generateRandomString(10); EventBus.instance().post(new TwitchFollowEvent(randomUser, this.channel)); } if (message.equalsIgnoreCase("hosttest")) { String randomUser = generateRandomString(10); EventBus.instance().post(new TwitchHostedEvent(randomUser, this.tcechannel)); } if (message.equals("debugoff")) { Quorrabot.setDebugging(false); } if (message.startsWith("inidb.get")) { String spl[] = message.split(" ", 4); com.gmt2001.Console.out.println(dataStoreObj.GetString(spl[1], spl[2], spl[3])); } if (message.startsWith("inidb.set")) { String spl[] = message.split(" ", 5); dataStoreObj.SetString(spl[1], spl[2], spl[3], spl[4]); com.gmt2001.Console.out.println(dataStoreObj.GetString(spl[1], spl[2], spl[3])); } if (message.equals("apioauth")) { com.gmt2001.Console.out.print("Please enter the bot owner's api oauth string: "); String newoauth = System.console().readLine().trim(); TwitchAPIv3.instance().SetOAuth(newoauth); apioauth = newoauth; changed = true; } if (message.equalsIgnoreCase("mysqlsetup")) { try { com.gmt2001.Console.out.println(""); com.gmt2001.Console.out.println("QuorraBot MySQL setup."); com.gmt2001.Console.out.println(""); com.gmt2001.Console.out.print("Please enter your MySQL host name or IP: "); String newHost = System.console().readLine().trim(); mySqlHost = newHost; com.gmt2001.Console.out.print("Please enter your MySQL port: "); String newPost = System.console().readLine().trim(); mySqlPort = newPost; com.gmt2001.Console.out.print("Please enter your MySQL db name: "); String newName = System.console().readLine().trim(); mySqlName = newName; com.gmt2001.Console.out.print("Please enter a username for MySQL: "); String newUser = System.console().readLine().trim(); mySqlUser = newUser; com.gmt2001.Console.out.print("Please enter a password for MySQL: "); String newPass = System.console().readLine().trim(); mySqlPass = newPass; datastore = "MySQLStore"; dataStoreObj = MySQLStore.instance(); if (mySqlPort.isEmpty()) { mySqlConn = "jdbc:mariadb://" + mySqlHost + "/" + mySqlName; } else { mySqlConn = "jdbc:mariadb://" + mySqlHost + ":" + mySqlPort + "/" + mySqlName; } /** * Check to see if we can create a connection */ if (dataStoreObj.CreateConnection(mySqlConn, mySqlUser, mySqlPass) == null) { com.gmt2001.Console.out .println("Could not create a connection with MySql. QuorraBot now shutting down..."); System.exit(0); } if (IniStore.instance().GetFileList().length > 0) { ini2MySql(true); } else if (SqliteStore.instance().GetFileList().length > 0) { sqlite2MySql(); } com.gmt2001.Console.out.println("QuorraBot MySQL setup done."); changed = true; } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } if (message.equals("clientid")) { com.gmt2001.Console.out.print("Please enter the bot api clientid string: "); String newclientid = System.console().readLine().trim(); TwitchAPIv3.instance().SetClientID(newclientid); clientid = newclientid; changed = true; } if (message.equals("baseport")) { com.gmt2001.Console.out.print("Please enter a new base port: "); String newbaseport = System.console().readLine().trim(); baseport = Integer.parseInt(newbaseport); changed = true; } if (message.equals("ip")) { com.gmt2001.Console.out.print("Please enter an IP address to bind to: "); String ipstr = System.console().readLine().trim(); try { InetAddress newip = InetAddress.getByName(ipstr); ip = newip; changed = true; } catch (UnknownHostException e) { com.gmt2001.Console.out.print("Error binding to IP address, please double check your IP entry."); return; } } if (message.equals("youtubekey")) { com.gmt2001.Console.out.print("Please enter a new YouTube API key: "); String newyoutubekey = System.console().readLine().trim(); YouTubeAPIv3.instance().SetAPIKey(newyoutubekey); youtubekey = newyoutubekey; changed = true; } if (message.equals("twitchalerts")) { com.gmt2001.Console.out.print("Please enter a new TwitchAlerts Access Token: "); String newtwitchalertstoken = System.console().readLine().trim(); DonationHandlerAPI.instance().SetAccessToken(newtwitchalertstoken, "twitchalerts"); twitchalertstoken = newtwitchalertstoken; changed = true; } if (message.equals("lastfm")) { com.gmt2001.Console.out.print("Please enter a last.fm username: "); String newlastfmuser = System.console().readLine().trim(); LastFMAPI.instance().SetUsername(newlastfmuser); lastfmuser = newlastfmuser; changed = true; } if (message.equals("tipeeestream")) { com.gmt2001.Console.out.print("Please enter a new Tipeeestream Access Token: "); String newtpetoken = System.console().readLine().trim(); DonationHandlerAPI.instance().SetAccessToken(newtpetoken, "tpestream"); tpetoken = newtpetoken; changed = true; } if (message.equals("twitter")) { com.gmt2001.Console.out .print("Please visit this url to grant QuorraBot twitter access, then enter your pin" + "\n"); com.gmt2001.Console.out.print(TwitterAPI.instance().getRequestTokenURL() + "\n"); com.gmt2001.Console.out.print("Twitter PIN:"); String newtwittertoken = System.console().readLine().trim(); TwitterAPI.instance().CreateAccessToken(newtwittertoken); twittertoken = TwitterAPI.instance().getAccessToken(); twittertokensecret = TwitterAPI.instance().getAccessTokenSecret(); changed = true; } if (message.equals("streamtip")) { com.gmt2001.Console.out.print("Please enter a new StreamTip Client ID: "); String newstreamtipid = System.console().readLine().trim(); DonationHandlerAPI.instance().SetClientID(newstreamtipid, "streamtip"); streamtipid = newstreamtipid; com.gmt2001.Console.out.print("Please enter a new StreamTip Access Token: "); String newstreamtiptoken = System.console().readLine().trim(); DonationHandlerAPI.instance().SetAccessToken(newstreamtiptoken, "streamtip"); streamtiptoken = newstreamtiptoken; changed = true; } if (message.equals("gamewisp")) { com.gmt2001.Console.out.print("Please enter a new GameWisp Access Token: "); String newgamewispauth = System.console().readLine().trim(); gamewispauth = newgamewispauth; GameWispAPI.instance().SetAccessToken(gamewispauth); SingularityAPI.instance().setAccessToken(gamewispauth); com.gmt2001.Console.out.print("Please enter a new GameWisp Refresh Token: "); String newgamewisprefresh = System.console().readLine().trim(); gamewisprefresh = newgamewisprefresh; GameWispAPI.instance().SetRefreshToken(gamewisprefresh); doRefreshGameWispToken(); changed = true; } if (message.equals("discord")) { com.gmt2001.Console.out.print("Please enter a new Discord Access Token: "); String newdiscordtoken = System.console().readLine().trim(); discordToken = newdiscordtoken; com.gmt2001.Console.out.print("Please enter the name of the discord channel for the bot to join: "); String newdiscordmainchannel = System.console().readLine().trim(); discordMainChannel = newdiscordmainchannel; changed = true; } if (message.equals("testgwrefresh")) { com.gmt2001.Console.out.println("[CONSOLE] Executing testgwrefresh"); updateGameWispTokens(GameWispAPI.instance().refreshToken()); changed = true; } if (message.equals("testgwsub")) { com.gmt2001.Console.out.println("[CONSOLE] Executing testgwsub"); EventBus.instance().post(new GameWispSubscribeEvent(this.username, 1)); return; } if (message.equals("testgwresub")) { com.gmt2001.Console.out.println("[CONSOLE] Executing testgwresub"); EventBus.instance().post(new GameWispAnniversaryEvent(this.username, 2, 3)); return; } if (message.equals("webenable")) { com.gmt2001.Console.out.print( "Please note that the music server will also be disabled if the web server is disabled. The bot will require a restart for this to take effect. Type true or false to enable/disable web server: "); String newwebenable = System.console().readLine().trim(); changed = true; if (newwebenable.equalsIgnoreCase("1") || newwebenable.equalsIgnoreCase("true")) { webenable = true; } else { webenable = false; } } if (message.equals("musicenable")) { if (!webenable) { com.gmt2001.Console.out.println("Web server must be enabled first. "); } else { com.gmt2001.Console.out.print( "The bot will require a restart for this to take effect. Please type true or false to enable/disable music server: "); String newmusicenable = System.console().readLine().trim(); changed = true; if (newmusicenable.equalsIgnoreCase("1") || newmusicenable.equalsIgnoreCase("true")) { musicenable = true; } else { musicenable = false; } } } if (changed) { try { String data = ""; data += "user=" + username + "\r\n"; data += "oauth=" + oauth + "\r\n"; data += "apioauth=" + apioauth + "\r\n"; data += "clientid=" + clientid + "\r\n"; data += "webauth=" + webauth + "\r\n"; data += "webauthro=" + webauthro + "\r\n"; data += "owner=" + ownerName + "\r\n"; data += "channel=" + channelName + "\r\n"; data += "baseport=" + baseport + "\r\n"; data += "ip=" + ip.getHostAddress() + "\r\n"; data += "hostname=" + hostname + "\r\n"; data += "port=" + port + "\r\n"; data += "msglimit30=" + msglimit30 + "\r\n"; data += "datastore=" + datastore + "\r\n"; data += "youtubekey=" + youtubekey + "\r\n"; data += "twitchalertstoken=" + twitchalertstoken + "\r\n"; data += "gamewispauth=" + gamewispauth + "\r\n"; data += "gamewisprefresh=" + gamewisprefresh + "\r\n"; data += "lastfmuser=" + lastfmuser + "\r\n"; data += "tpetoken=" + tpetoken + "\r\n"; data += "twittertoken=" + twittertoken + "\r\n"; data += "twittertokensecret=" + twittertokensecret + "\r\n"; data += "streamtiptoken=" + streamtiptoken + "\r\n"; data += "streamtipid=" + streamtipid + "\r\n"; data += "webenable=" + webenable + "\r\n"; data += "musicenable=" + musicenable + "\r\n"; data += "usehttps=" + usehttps + "\r\n"; data += "logtimezone=" + timeZone + "\r\n"; data += "mysqlhost=" + mySqlHost + "\r\n"; data += "mysqlport=" + mySqlPort + "\r\n"; data += "mysqlname=" + mySqlName + "\r\n"; data += "mysqluser=" + mySqlUser + "\r\n"; data += "mysqlpass=" + mySqlPass + "\r\n"; data += "keystorepath=" + keystorepath + "\r\n"; data += "discordtoken=" + discordToken + "\r\n"; data += "discordmainchannel=" + discordMainChannel + "\r\n"; Files.write(Paths.get("./botlogin.txt"), data.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); SingularityAPI.instance().setAccessToken(gamewispauth); if (webenable) { com.gmt2001.Console.out.println("[SHUTDOWN] Terminating web server..."); eventsocketserver.dispose(); if (musicenable) { com.gmt2001.Console.out.println("[SHUTDOWN] Terminating music server..."); musicsocketserver.dispose(); } httpserver.dispose(); startWebServices(); } if (!discordToken.isEmpty()) { DiscordAPI.instance().reconnect(); connectDiscord(); } com.gmt2001.Console.out.println( "Changes have been saved! Some changes may only take place after QuorraBot is restarted."); } catch (IOException ex) { com.gmt2001.Console.err.printStackTrace(ex); } } if (message.equals("save")) { dataStoreObj.SaveAll(true); } if (message.equals("quicksave")) { dataStoreObj.SaveChangedNow(); } if (message.equals("exit")) { System.exit(0); } Map<String, String> tags = new HashMap<>(); handleCommand(username, message, tags, channel, ownerName); }
From source file:org.openconcerto.sql.PropsConfiguration.java
public void setupLogging(final String dirName, final boolean redirectToFile) { final File logDir; synchronized (this.restLock) { if (this.logDir != null) throw new IllegalStateException("Already set to " + this.logDir); logDir = getValidLogDir(dirName); this.logDir = logDir; }// ww w. j av a 2s . c o m final String logNameBase = this.getAppName() + "_" + getLogDateFormat().format(new Date()); // must be done before setUpConsoleHandler(), otherwise log output not redirected if (redirectToFile) { final File logFile = new File(logDir, (logNameBase + ".txt")); try { FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Log file: " + logFile.getAbsolutePath()); final OutputStream fileOut = new FileOutputStream(logFile, true); final OutputStream out, err; System.out.println("Java System console:" + System.console()); boolean launchedFromEclipse = new File(".classpath").exists(); if (launchedFromEclipse) { System.out.println("Launched from eclipse"); } if ((System.console() != null || launchedFromEclipse) && this.keepStandardStreamsWhenRedirectingToFile()) { System.out.println("Redirecting standard output to file and console"); out = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.out)); System.out.println("Redirecting error output to file and console"); err = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.err)); } else { out = fileOut; err = fileOut; } System.setErr(new PrintStream(new BufferedOutputStream(err, 128), true)); System.setOut(new PrintStream(new BufferedOutputStream(out, 128), true)); // Takes about 350ms so run it async new Thread(new Runnable() { @Override public void run() { try { FileUtils.ln(logFile, new File(logDir, "last.log")); } catch (final IOException e) { // the link is not important e.printStackTrace(); } } }).start(); } catch (final Exception e) { ExceptionHandler.handle("Redirection des sorties standards impossible", e); } } else { System.out.println("Standard streams not redirected to file"); } // removes default LogUtils.rmRootHandlers(); // add console handler LogUtils.setUpConsoleHandler(); // add file handler (supports concurrent launches, doesn't depend on date) try { final File logFile = new File(logDir, this.getAppName() + "-%u-age%g.log"); FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Logger logs: " + logFile.getAbsolutePath()); // 2 files of at most 5M, each new launch append // if multiple concurrent launches %u is used final FileHandler fh = new FileHandler(logFile.getPath(), 5 * 1024 * 1024, 2, true); fh.setFormatter(new SimpleFormatter()); Logger.getLogger("").addHandler(fh); } catch (final Exception e) { ExceptionHandler.handle("Enregistrement du Logger dsactiv", e); } this.setLoggersLevel(); }
From source file:com.cloudera.sqoop.SqoopOptions.java
/** * Allow the user to enter his password on the console without printing * characters./*from w w w. j ava 2s. com*/ * @return the password as a string */ private String securePasswordEntry() { return new String(System.console().readPassword("Enter password: ")); }