List of usage examples for java.lang String startsWith
public boolean startsWith(String prefix)
From source file:com.linkedin.kmf.KafkaMonitor.java
public static void main(String[] args) throws Exception { if (args.length <= 0) { LOG.info("USAGE: java [options] " + KafkaMonitor.class.getName() + " config/kafka-monitor.properties"); return;//from w ww .jav a 2 s . c o m } StringBuilder buffer = new StringBuilder(); try (BufferedReader br = new BufferedReader(new FileReader(args[0].trim()))) { String line; while ((line = br.readLine()) != null) { if (!line.startsWith("#")) buffer.append(line); } } @SuppressWarnings("unchecked") Map<String, Map> props = new ObjectMapper().readValue(buffer.toString(), Map.class); KafkaMonitor kafkaMonitor = new KafkaMonitor(props); kafkaMonitor.start(); LOG.info("KafkaMonitor started"); kafkaMonitor.awaitShutdown(); }
From source file:eu.annocultor.converters.geonames.GeonamesDumpToRdf.java
public static void main(String[] args) throws Exception { File root = new File("input_source"); // load country-continent match countryToContinent/*from www .j a v a2s .co m*/ .load((new GeonamesDumpToRdf()).getClass().getResourceAsStream("/country-to-continent.properties")); // creating files Map<String, BufferedWriter> files = new HashMap<String, BufferedWriter>(); Map<String, Boolean> started = new HashMap<String, Boolean>(); for (Object string : countryToContinent.keySet()) { String continent = countryToContinent.getProperty(string.toString()); File dir = new File(root, continent); if (!dir.exists()) { dir.mkdir(); } files.put(string.toString(), new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File(root, continent + "/" + string + ".rdf")), "UTF-8"))); System.out.println(continent + "/" + string + ".rdf"); started.put(string.toString(), false); } System.out.println(started); Pattern countryPattern = Pattern .compile("<inCountry rdf\\:resource\\=\"http\\://www\\.geonames\\.org/countries/\\#(\\w\\w)\"/>"); long counter = 0; LineIterator it = FileUtils.lineIterator(new File(root, "all-geonames-rdf.txt"), "UTF-8"); try { while (it.hasNext()) { String text = it.nextLine(); if (text.startsWith("http://sws.geonames")) continue; // progress counter++; if (counter % 100000 == 0) { System.out.print("*"); } // System.out.println(counter); // get country String country = null; Matcher matcher = countryPattern.matcher(text); if (matcher.find()) { country = matcher.group(1); } // System.out.println(country); if (country == null) country = "null"; text = text.replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><rdf:RDF", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><rdf:RDF"); if (started.get(country) == null) throw new Exception("Unknow country " + country); if (started.get(country).booleanValue()) { // remove RDF opening text = text.substring(text.indexOf("<rdf:RDF ")); text = text.substring(text.indexOf(">") + 1); } // remove RDF ending text = text.substring(0, text.indexOf("</rdf:RDF>")); files.get(country).append(text + "\n"); if (!started.get(country).booleanValue()) { // System.out.println("Started with country " + country); } started.put(country, true); } } finally { LineIterator.closeQuietly(it); } for (Object string : countryToContinent.keySet()) { boolean hasStarted = started.get(string.toString()).booleanValue(); if (hasStarted) { BufferedWriter bf = files.get(string.toString()); bf.append("</rdf:RDF>"); bf.flush(); bf.close(); } } return; }
From source file:ResultSetMetaDataExample.java
public static void main(String args[]) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", ""); Statement stmt = con.createStatement(); boolean notDone = true; String sqlStr = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (notDone) { sqlStr = br.readLine();/*w w w .j a v a 2s. c om*/ if (sqlStr.startsWith("SELECT") || sqlStr.startsWith("select")) { ResultSet rs = stmt.executeQuery(sqlStr); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); for (int x = 1; x <= columnCount; x++) { String columnName = rsmd.getColumnName(x); System.out.print(columnName); } while (rs.next()) { for (int x = 1; x <= columnCount; x++) { if (rsmd.getColumnTypeName(x).compareTo("CURRENCY") == 0) System.out.print("$"); String resultStr = rs.getString(x); System.out.print(resultStr + "\t"); } } } else if (sqlStr.startsWith("exit")) notDone = false; } stmt.close(); con.close(); }
From source file:com.alibaba.otter.manager.deployer.OtterManagerLauncher.java
public static void main(String[] args) throws Throwable { try {//ww w.j a va2s . c o m String conf = System.getProperty("otter.conf", "classpath:otter.properties"); Properties properties = new Properties(); if (conf.startsWith(CLASSPATH_URL_PREFIX)) { conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX); properties.load(OtterManagerLauncher.class.getClassLoader().getResourceAsStream(conf)); } else { properties.load(new FileInputStream(conf)); } // ??system? mergeProps(properties); logger.info("## start the manager server."); final JettyEmbedServer server = new JettyEmbedServer( properties.getProperty("otter.jetty", "jetty.xml")); server.start(); logger.info("## the manager server is running now ......"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { logger.info("## stop the manager server"); server.join(); } catch (Throwable e) { logger.warn("##something goes wrong when stopping manager Server:\n{}", ExceptionUtils.getFullStackTrace(e)); } finally { logger.info("## manager server is down."); } } }); } catch (Throwable e) { logger.error("## Something goes wrong when starting up the manager Server:\n{}", ExceptionUtils.getFullStackTrace(e)); System.exit(0); } }
From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java
/** * @param args//from ww w.ja v a 2s. c o m */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER"); File binDir = ClasspathUtils.getClassesDir(); File projectDir = binDir.getParentFile(); // File dryrunDir = new File(projectDir, "dryrun"); File licenceFile = new File(licenceHeaderURL.toURI()); List<String> licenceLines = readLines(licenceFile); // for (int i = 0; i < licenceLines.size(); i++) { // String licenceLine = licenceLines.get(i); // licenceLines.set(i, " * " + licenceLine); // } // licenceLines.add(0, "/**"); // licenceLines.add(" */"); List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir, new String[] { "java" }, true); for (File javaFile : javaFiles) { if (isValidPackage(javaFile)) { List<String> javaFileLines = readLines(javaFile); if (!javaFileLines.isEmpty()) { boolean modified = false; String firstLineTrim = javaFileLines.get(0).trim(); if (firstLineTrim.startsWith("package")) { modified = true; javaFileLines.addAll(0, licenceLines); } else if (firstLineTrim.startsWith("/**")) { int indexOfEndCommentLine = -1; loop2: for (int i = 0; i < javaFileLines.size(); i++) { String javaFileLine = javaFileLines.get(i); if (javaFileLine.indexOf("*/") != -1) { indexOfEndCommentLine = i; break loop2; } } if (indexOfEndCommentLine != -1) { modified = true; int i = 0; loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) { it.next(); if (i <= indexOfEndCommentLine) { it.remove(); } else { break loop3; } i++; } javaFileLines.addAll(0, licenceLines); } else { throw new RuntimeException( "Missing end comment for file " + javaFile.getAbsolutePath()); } } if (modified) { // String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length()); // File outputFile = new File(dryrunDir, outputFilePath); // outputFile.getParentFile().mkdirs(); // System.out.println(outputFile.getPath()); // FileOutputStream fos = new FileOutputStream(outputFile); System.out.println(javaFile.getPath()); FileOutputStream fos = new FileOutputStream(javaFile); IOUtils.writeLines(javaFileLines, "\n", fos); IOUtils.closeQuietly(fos); } } } } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(443); while (true) { Socket s = ss.accept();/*from w w w .j av a2s .com*/ PrintStream out = new PrintStream(s.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String info = null; String request = null; String refer = null; while ((info = in.readLine()) != null) { if (info.startsWith("GET")) { request = info; } if (info.startsWith("Referer:")) { refer = info; } if (info.equals("")) break; } if (request != null) { out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html"); int sp1 = request.indexOf(' '); int sp2 = request.indexOf(' ', sp1 + 1); String filename = request.substring(sp1 + 2, sp2); if (refer != null) { sp1 = refer.indexOf(' '); refer = refer.substring(sp1 + 1, refer.length()); if (!refer.endsWith("/")) { refer = refer + "/"; } filename = refer + filename; } URL con = new URL(filename); InputStream gotoin = con.openStream(); int n = gotoin.available(); byte buf[] = new byte[1024]; out.println("HTTP/1.0 200 OK\nMIME_version:1.0\nContent_Type:text/html"); out.println("Content_Length:" + n + "\n"); while ((n = gotoin.read(buf)) >= 0) { out.write(buf, 0, n); } out.close(); s.close(); in.close(); } } }
From source file:au.csiro.casda.sodalint.SodaLinter.java
/** * Command line handler for SodaLinter//from w ww .j a va 2 s .c om * @param args The command line arguments * @throws Exception If an otherwise uncaught error occurs. */ public static void main(String[] args) throws Exception { SodaLinter linter = new SodaLinter(); String[] stages = null; final int defaultMaxRepeat = 9; final int defaultMaxLineLen = 1024; int maxRepeat = defaultMaxRepeat; int maxLineLen = defaultMaxLineLen; String sodaUrl = null; boolean error = false; for (String arg : args) { if (arg.startsWith("stages=")) { stages = arg.substring("stages=".length()).split(" "); } else if (arg.startsWith("maxrepeat=")) { String value = arg.substring("maxrepeat=".length()); if (StringUtils.isNumeric(value)) { maxRepeat = Integer.parseInt(value); } else { error = true; } } else if (arg.startsWith("truncate=")) { String value = arg.substring("truncate=".length()); if (StringUtils.isNumeric(value)) { maxLineLen = Integer.parseInt(value); } else { error = true; } } else { sodaUrl = arg.startsWith("sodaurl=") ? arg.substring("sodaurl=".length()) : arg; } } if (sodaUrl == null || error) { System.out.println( "Usage: java -jar sodalint-full.jar [stages=\"CPV|CAP|AVV|EXM|SVD|ERR|SYN|ASY[ ...]\"] " + "[maxrepeat=<int-value>] [truncate=<int-value>] [sodaurl=]<url-value>"); System.exit(1); } TextOutputReporter reporter = new TextOutputReporter(System.out, ReportType.values(), maxRepeat, false, maxLineLen); // URL serviceUrl = new URL("https://casda-dev-app.pawsey.org.au/casda_data_access/data/"); URL serviceUrl = new URL(sodaUrl); String[] defaultStages = new String[] { Stage.CAP_XML.getCode(), Stage.AVAIL_XML.getCode(), Stage.CAPABILITIES.getCode(), Stage.SYNC.getCode(), Stage.ASYNC.getCode(), Stage.SERVICE_DESC.getCode() }; Set<String> codes = new HashSet<>(Arrays.asList(stages != null ? stages : defaultStages)); Executable executable = linter.createExecutable(reporter, serviceUrl, codes, null); executable.execute(); }
From source file:TestReadCustData.java
public static void main(String[] args) { AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1"); List<Customer> lCust = new ArrayList<>(); try {//w ww.j a va 2 s . c o m List<String> s = Files.readAllLines(Paths.get("customer.txt"), Charsets.ISO_8859_1); for (String s1 : s) { if (!s1.startsWith("GRUP")) { Customer c = new Customer(); try { c.setId(Long.parseLong(s1.split("~")[3])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setId(Long.parseLong(s1.split("~")[3])); } try { c.setNama(s1.split("~")[4]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNama(""); } try { c.setShipto(s1.split("~")[9]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setShipto(""); } try { c.setKota(s1.split("~")[12]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKota(""); } try { c.setProvinsi(s1.split("~")[13]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setProvinsi(""); } try { c.setKodePos(s1.split("~")[14]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKodePos(""); } try { c.setNamaArea(s1.split("~")[2]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaArea(""); } try { c.setDKLK(s1.split("~")[15]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setDKLK(""); } try { c.setCreditLimit(Long.parseLong(s1.split("~")[16])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreditLimit(new Long(0)); } try { c.setNpwp(s1.split("~")[11]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNpwp(""); } try { c.setNamaWajibPajak(s1.split("~")[10]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaWajibPajak(""); } try { c.setCreationDate(s1.split("~")[6]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreationDate(""); } try { c.setLastUpdateBy(s1.split("~")[17]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateBy(""); } try { c.setLastUpdateDate(s1.split("~")[18]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateDate(""); } lCust.add(c); } } for (Customer c : lCust) { Customer cc = Ebean.find(Customer.class, c.getId()); if (cc != null) { cc = c; Ebean.update(cc); } System.out.print(c.getId()); System.out.print(" | "); System.out.print(c.getNama()); System.out.print(" | "); System.out.print(c.getShipto()); System.out.print(" | "); System.out.print(c.getNpwp()); System.out.print(" | "); System.out.print(c.getNamaWajibPajak()); System.out.println(); } } catch (IOException ex) { Logger.getLogger(TestReadCustData.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.nira.wso2.nexus.ComponentVersion.java
public static void main(String[] args) { urlList.add(Constants.REPO_MAVEN);/*from w ww .j a va 2 s.com*/ urlList.add(Constants.REPO_MAVEN_WSO2_RELEASES); urlList.add(Constants.REPO_MAVEN_WSO2_PUBLIC); String pomFilePath = ""; boolean ignoreSameVersion = false; for (String arg : args) { if (arg.startsWith(Constants.CMD_POM_FILE)) { pomFilePath = arg.substring(Constants.CMD_POM_FILE.length() + 1); } else if (arg.startsWith(Constants.CMD_IGNORE_SAME_VERSION)) { String param = arg.substring(Constants.CMD_IGNORE_SAME_VERSION.length() + 1); if ("true".equals(param)) { ignoreSameVersion = true; } } } // pomFilePath = "C:\\Users\\Nira\\Desktop\\as_pom.xml"; if (pomFilePath.isEmpty()) { throw new ComponentException("Pom File path not specified!"); } readPomFile(pomFilePath); displayComponents(ignoreSameVersion); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.ClusterCentroidsMain.java
public static void main(String[] args) throws Exception { // String clutoVectors = args[0]; // String clutoOuputClusters = args[1]; // String outputClusterCentroids = args[2]; File[] files = new File("//home/user-ukp/data2/debates-ranked.100-xmi").listFiles(new FilenameFilter() { @Override//w w w . ja va 2s.c o m public boolean accept(File dir, String name) { // return name.startsWith("arg") && name.endsWith(".mat"); return name.startsWith("sent") && name.endsWith(".mat"); } }); for (File matFile : files) { String clutoVectors = matFile.getAbsolutePath(); // String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.100"; String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.1000"; String outputClusterCentroids = matFile.getAbsolutePath() + ".bin"; TreeMap<Integer, Vector> centroids = computeClusterCentroids(clutoVectors, clutoOuputClusters); // and serialize ObjectOutputStream objectOutputStream = new ObjectOutputStream( new FileOutputStream(outputClusterCentroids)); objectOutputStream.writeObject(centroids); IOUtils.closeQuietly(objectOutputStream); } // System.out.println(centroids); // embeddingsToDistance(args[0], centroids, args[2]); }