List of usage examples for java.lang StringBuffer StringBuffer
public StringBuffer(CharSequence seq)
From source file:fr.inria.edelweiss.kgdqp.core.FedQueryingCLI.java
@SuppressWarnings("unchecked") public static void main(String args[]) throws ParseException, EngineException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;/*from w w w . j ava2 s . c om*/ int slice = -1; Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); Option endpointOpt = new Option("e", "endpoints", true, "the list of federated sparql endpoint URLs"); Option groupingOpt = new Option("g", "grouping", true, "triple pattern optimisation"); Option slicingOpt = new Option("s", "slicing", true, "size of the slicing parameter"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); options.addOption(queryOpt); options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(groupingOpt); options.addOption(slicingOpt); String header = "Corese/KGRAM DQP command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (!cmd.hasOption("e")) { logger.info("You must specify at least the URL of one sparql endpoint !"); System.exit(0); } else { endpoints = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("e"))); } if (!cmd.hasOption("q")) { logger.info("You must specify a path for a sparql query !"); System.exit(0); } else { queryPath = cmd.getOptionValue("q"); } if (cmd.hasOption("s")) { try { slice = Integer.parseInt(cmd.getOptionValue("s")); } catch (NumberFormatException ex) { logger.warn(cmd.getOptionValue("s") + " is not formatted as number for the slicing parameter"); logger.warn("Slicing disabled"); } } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } ///////////////// Graph graph = Graph.create(); QueryProcessDQP exec = QueryProcessDQP.create(graph); exec.setGroupingEnabled(cmd.hasOption("g")); if (slice > 0) { exec.setSlice(slice); } Provider sProv = ProviderImplCostMonitoring.create(); exec.set(sProv); for (String url : endpoints) { try { exec.addRemote(new URL(url), WSImplem.REST); } catch (MalformedURLException ex) { logger.error(url + " is not a well-formed URL"); System.exit(1); } } StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(queryPath)); } catch (FileNotFoundException ex) { logger.error("Query file " + queryPath + " not found !"); System.exit(1); } char[] buf = new char[1024]; int numRead = 0; try { while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; } reader.close(); } catch (IOException ex) { logger.error("Error while reading query file " + queryPath); System.exit(1); } String sparqlQuery = fileData.toString(); // Query q = exec.compile(sparqlQuery, null); // System.out.println(q); StopWatch sw = new StopWatch(); sw.start(); Mappings map = exec.query(sparqlQuery); int dqpSize = map.size(); System.out.println("--------"); long time = sw.getTime(); System.out.println(time + " " + dqpSize); }
From source file:edu.uga.cs.fluxbuster.FluxbusterCLI.java
/** * The main method.// w w w. j a v a2 s . co m * * @param args the command line arguments */ public static void main(String[] args) { GnuParser parser = new GnuParser(); Options opts = FluxbusterCLI.initializeOptions(); CommandLine cli; try { cli = parser.parse(opts, args); if (cli.hasOption('?')) { throw new ParseException(null); } if (validateDate(cli.getOptionValue('d')) && validateDate(cli.getOptionValue('e'))) { if (log.isInfoEnabled()) { StringBuffer arginfo = new StringBuffer("\n"); arginfo.append("generate-clusters: " + cli.hasOption('g') + "\n"); arginfo.append("calc-features: " + cli.hasOption('f') + "\n"); arginfo.append("calc-similarity: " + cli.hasOption('s') + "\n"); arginfo.append("classify-clusters: " + cli.hasOption('c') + "\n"); arginfo.append("start-date: " + cli.getOptionValue('d') + "\n"); arginfo.append("end-date: " + cli.getOptionValue('e') + "\n"); log.info(arginfo.toString()); } try { boolean clus = true, feat = true, simil = true, clas = true; if (cli.hasOption('g') || cli.hasOption('f') || cli.hasOption('s') || cli.hasOption('c')) { if (!cli.hasOption('g')) { clus = false; } if (!cli.hasOption('f')) { feat = false; } if (!cli.hasOption('s')) { simil = false; } if (!cli.hasOption('c')) { clas = false; } } DBInterfaceFactory.init(); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); Date logdate = df.parse(cli.getOptionValue('d')); long startTime = logdate.getTime() / 1000; long endTime = df.parse(cli.getOptionValue('e')).getTime() / 1000; if (clus) { ClusterGenerator cg = new ClusterGenerator(); List<DomainCluster> clusters = cg.generateClusters(startTime, endTime, true); cg.storeClusters(clusters, logdate); } if (feat) { FeatureCalculator calc = new FeatureCalculator(); calc.updateFeatures(logdate); } if (simil) { ClusterSimilarityCalculator calc2 = new ClusterSimilarityCalculator(); calc2.updateClusterSimilarities(logdate); } if (clas) { Classifier calc3 = new Classifier(); calc3.updateClusterClasses(logdate, 30); } } catch (Exception e) { if (log.isFatalEnabled()) { log.fatal("", e); } } finally { DBInterfaceFactory.shutdown(); } } else { throw new ParseException(null); } } catch (ParseException e1) { PrintWriter writer = new PrintWriter(System.out); HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(writer, 80, "fluxbuster", "If none of the options g, f, s, c are specified " + "then the program will execute as if all of them " + "have been specified. Otherwise, the program will " + "only execute the options specified.", opts, 0, 2, ""); writer.close(); } }
From source file:Main.java
static String formatDateTime(String mmdd, String hhmmss) { return new StringBuffer(hhmmss).insert(4, ":").insert(2, ":").insert(0, ' ').insert(0, mmdd).insert(2, "/") .toString();// w ww .j av a2s . c om }
From source file:Main.java
public static String toString(byte b) { StringBuffer sb = new StringBuffer(2); int i = (b & 0xF0) >> 4; int j = b & 0x0F; sb.append(new Character((char) ((i > 9) ? (65 + i - 10) : (48 + i)))); sb.append(new Character((char) ((j > 9) ? (65 + j - 10) : (48 + j)))); return sb.toString(); }
From source file:Main.java
private static String join(int length) { StringBuffer sb = new StringBuffer(1024); for (int i = 0; i < length; i++) { sb.append("?,"); }/* w w w . j av a 2 s.c o m*/ if (sb.charAt(sb.length() - 1) == ',') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:Main.java
public static String toHex(byte[] buffer) { StringBuffer sb = new StringBuffer(buffer.length * 2); for (int i = 0; i < buffer.length; i++) { sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16)); sb.append(Character.forDigit(buffer[i] & 15, 16)); }/*from w w w .ja v a 2 s . com*/ return sb.toString(); }
From source file:Main.java
public static String byte2hex(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); String tmp = ""; for (int n = 0; n < b.length; n++) { tmp = (Integer.toHexString(b[n] & 0XFF)); if (tmp.length() == 1) { sb.append("0"); }/* w w w. j ava 2 s. c o m*/ sb.append(tmp); } return sb.toString().toUpperCase(); }
From source file:Main.java
public static String byte2hex(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); String tmp = ""; for (int n = 0; n < b.length; n++) { tmp = (java.lang.Integer.toHexString(b[n] & 0XFF)); if (tmp.length() == 1) { sb.append("0"); }//from ww w .ja v a 2 s . c o m sb.append(tmp); } return sb.toString().toUpperCase(); }
From source file:Main.java
public static String toHex(final byte[] b) { final StringBuffer sb = new StringBuffer(b.length * 3); for (int i = 0; i < b.length; ++i) { sb.append(Character.forDigit((b[i] & 0xF0) >> 4, 16)); sb.append(Character.forDigit(b[i] & 0xF, 16)); }// ww w. j a va 2s .co m return ((sb != null) ? sb.toString().toUpperCase() : null); }
From source file:Main.java
public static String Bcd2Str(byte[] bytes) { StringBuffer temp = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { temp.append((byte) ((bytes[i] & 0xf0) >>> 4)); temp.append((byte) (bytes[i] & 0x0f)); }/*w w w. j a v a 2s . c o m*/ return temp.toString(); }