List of usage examples for java.lang String split
public String[] split(String regex)
From source file:com.axiomine.largecollections.generator.GeneratorPrimitivePrimitive.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from w w w .j a v a 2 s. c o m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[3]; //Class name (no packages) of the Key class Ex. String String K = args[4]; //Class name (no packages) of the value class Ex. Integer String V = args[5]; String kCls = K; String vCls = V; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = kCls + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/JavaLangBasedMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#V#", V); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#VCLS#", vCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); program = program.replaceAll("#VPACKAGE#", VPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorWritableKeyPrimitiveValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];//from www.ja v a 2 s . c o m //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[3]; //Class name (no packages) of the Key class Ex. String String K = args[4]; //Class name (no packages) of the value class Ex. Integer String V = args[5]; String kCls = K; String vCls = V; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = kCls + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString(new File( root.getAbsolutePath() + "/src/main/resources/WritableKeyPrimitiveValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#V#", V); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#VCLS#", vCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); program = program.replaceAll("#VPACKAGE#", VPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorWritableKeyWritableValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from ww w .j a v a 2 s. c o m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[3]; //Class name (no packages) of the Key class Ex. String String K = args[4]; //Class name (no packages) of the value class Ex. Integer String V = args[5]; String kCls = K; String vCls = V; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = kCls + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString(new File( root.getAbsolutePath() + "/src/main/resources/WritableKeyWritableValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#V#", V); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#VCLS#", vCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); program = program.replaceAll("#VPACKAGE#", VPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * @param args//from ww w. j a va 2 s .c o m */ public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { // This is for Windows and Exe4J, turn the args into System Properties for (String s : args) { String[] pairs = s.split("="); //$NON-NLS-1$ if (pairs.length == 2) { if (pairs[0].startsWith("-D")) //$NON-NLS-1$ { System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]); } } } // Then set this IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ new RegisterApp().doStart(); } }); }
From source file:LamportBasicVersion.java
public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException { totalMessageCount = 0;// ww w .ja v a2 s . c o m //For parsing the file and storing the information String line; String configurationFile = "configuration.txt"; int lineCountInFile = 0; myProcessId = Integer.parseInt(args[0]); FileReader fileReader = new FileReader(configurationFile); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { if ((!(line.startsWith("#"))) && (!(line.isEmpty()))) { lineCountInFile = lineCountInFile + 1; String[] splitLine = line.split(" "); switch (lineCountInFile) { case 1: numberOfProcesses = Integer.parseInt(splitLine[0]); interRequestDelay = Integer.parseInt(splitLine[1]); csExecutionTime = Integer.parseInt(splitLine[2]); maxNumberOfRequest = Integer.parseInt(splitLine[3]); machineNames = new String[Integer.parseInt(splitLine[0])]; portNumbers = new int[Integer.parseInt(splitLine[0])]; break; default: machineNames[lineCountInFile - 2] = splitLine[1]; portNumbers[lineCountInFile - 2] = Integer.parseInt(splitLine[2]); break; } } } conditionArray = new int[numberOfProcesses]; finishFlagArray = new int[numberOfProcesses]; //Initializing vector class VectorClass.initialize(numberOfProcesses); //Fill the arrays with zero false value for (int o = 0; o < numberOfProcesses; o++) { conditionArray[o] = 0; finishFlagArray[o] = 0; } // Write output to file filename = filename + Integer.toString(myProcessId) + ".out"; file = new File(filename); file.createNewFile(); writer = new FileWriter(file); // Write clocks to file filenameClock = filenameClock + Integer.toString(myProcessId) + ".out"; fileClock = new File(filenameClock); fileClock.createNewFile(); //writerClock = new FileWriter(fileClock); fw = new FileWriter(fileClock); bw = new BufferedWriter(fw); // // Expo mean insert csExecutionExpoDelay = new ExponentialDistribution(csExecutionTime); interRequestExpoDelay = new ExponentialDistribution(interRequestDelay); // System.out.println("********************************************************"); System.out.println("My process id : " + myProcessId); System.out.println("Number of processes : " + numberOfProcesses); System.out.println("Inter-request delay : " + interRequestDelay); System.out.println("Critical section execution time : " + csExecutionTime); System.out.println("Maximum number of request : " + maxNumberOfRequest); System.out.println( "My process name : " + machineNames[myProcessId] + " My port number : " + portNumbers[myProcessId]); for (int i = 0; i < numberOfProcesses; i++) { System.out.println("Process name : " + machineNames[i] + " Port number : " + portNumbers[i]); } System.out.println("********************************************************"); //For hosting server localhost SctpServerChannel sctpServerChannel = SctpServerChannel.open(); InetSocketAddress serverAddr = new InetSocketAddress(portNumbers[myProcessId]); sctpServerChannel.bind(serverAddr); System.out.println("********************************************************"); System.out.println("Local server hosted"); System.out.println("********************************************************"); //For creating neighbor SCTP channels Thread.sleep(30000); socketAddress = new SocketAddress[numberOfProcesses]; sctpChannel = new SctpChannel[numberOfProcesses]; System.out.println("********************************************************"); System.out.println("Neighbor channels created"); System.out.println("********************************************************"); //Thread spanned for generating critical section request new Thread(new LamportBasicVersion()).start(); //while loop to receive all the requests and other messages while (true) { try (SctpChannel sctpChannelFromClient = sctpServerChannel.accept()) { mutex.acquire(); byteBufferFromNeighbor.clear(); String receiveMessage; MessageInfo messageInfoFromNeighbor = sctpChannelFromClient.receive(byteBufferFromNeighbor, null, null); //System.out.println("Raw Message : " + messageInfoFromNeighbor); receiveMessage = byteToString(byteBufferFromNeighbor, messageInfoFromNeighbor); //write to file start writer.write("Received Message : " + receiveMessage); writer.write("\n"); writer.flush(); //write to file end System.out.println("Received Message : " + receiveMessage); if (receiveMessage.contains("Request")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // int requestMade = Integer.parseInt(parseMessage[3] + parseMessage[1]); queue.add(requestMade); //Send reply messages to that process for entering CS lamportClock++; //vector clock construction int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // for (int k = 0; k < numberOfProcesses; k++) { if (k == Integer.parseInt(parseMessage[1])) { try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[k].connect(socketAddress[k]); String sendMessage = "Reply from Process-" + myProcessId + "-" + Integer.toString(requestMade) + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); //write to file start writer.write("Message sent is : " + sendMessage); writer.write("\n"); writer.flush(); //write to file end MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[k].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[k].close(); } catch (IOException ex) { Logger.getLogger(LamportBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } } } else if (receiveMessage.contains("Reply")) { conditionArray[myProcessId] = 1; String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // conditionArray[Integer.parseInt(parseMessage[1])] = 1; int count = 0; for (int v = 0; v < numberOfProcesses; v++) { if (conditionArray[v] == 1) { count = count + 1; } } if (count == numberOfProcesses) { L1ConditionFlag = 1; System.out.println("Inside L1"); blockingQueue.put("L1"); //Clearing condition array after receiving all REPLY for (int z = 0; z < numberOfProcesses; z++) { conditionArray[z] = 0; } if (L2ConditionFlag == 0 && outstandingRequest == 1) { Integer[] queueArray = new Integer[queue.size()]; queue.toArray(queueArray); Arrays.sort(queueArray); if (queueArray[0] == currentRequestBeingServed) { System.out.println("Inside L2"); L2ConditionFlag = 1; blockingQueue.put("L2"); } } } } else if (receiveMessage.contains("Release")) { int present = 0; int delete = 0; String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // if (queue.size() != 0) { Integer[] queueArray = new Integer[queue.size()]; queue.toArray(queueArray); Arrays.sort(queueArray); for (int a = 0; a < queueArray.length; a++) { if (queueArray[a] == Integer.parseInt(parseMessage[2])) { present = 1; delete = a; } } if (present == 1) { for (int s = 0; s <= delete; s++) { queue.remove(); } } } if (L2ConditionFlag == 0 && outstandingRequest == 1) { if (queue.size() != 0) { Integer[] queueArray1 = new Integer[queue.size()]; queue.toArray(queueArray1); Arrays.sort(queueArray1); if (currentRequestBeingServed == queueArray1[0]) { L2ConditionFlag = 1; System.out.println("Inside L2"); blockingQueue.put("L2"); } } } } else if (receiveMessage.contains("Finish")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // finishFlagArray[Integer.parseInt(parseMessage[1])] = 1; int count = 0; for (int v = 0; v < numberOfProcesses; v++) { if (finishFlagArray[v] == 1) { count = count + 1; } } if (count == numberOfProcesses) { break; } } //logic for other messages //Print the queue to check System.out.println("********************************************************"); for (Object item : queue) { System.out.print(item); System.out.print("\t"); } System.out.println("********************************************************"); } mutex.release(); } }
From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyWritableValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from w ww. j av a2 s. c o m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[3]; //Class name (no packages) of the Key class Ex. String String K = args[4]; //Class name (no packages) of the value class Ex. Integer String V = args[5]; String vWritableCls = args[6]; String kCls = K; String vCls = V; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = kCls + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString(new File( root.getAbsolutePath() + "/src/main/resources/PrimitiveKeyWritableValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#V#", V); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#VCLS#", vCls); program = program.replaceAll("#VWRITABLECLS#", vWritableCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); program = program.replaceAll("#VPACKAGE#", VPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.ailk.oci.ocnosql.tools.load.single.SingleColumnImportTsv.java
/** * Main entry point./*from ww w . j a v a 2 s.c o m*/ * * @param args The command line parameters. * @throws Exception When running the job fails. */ public static void main(String[] args) throws Exception { Map<String, String> map = getProperty(); if (map == null || map.size() == 0) { System.err.println("Error: read conf file " + CONF_FILE + " occur error."); System.exit(0); } Configuration conf = Connection.getInstance().getConf(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 2) { usage("Wrong number of arguments: " + otherArgs.length); System.exit(-1); } // Make sure columns are specified String columns = conf.get(CommonConstants.COLUMNS); if (columns == null) { usage("No columns specified. Please specify with -D" + CommonConstants.COLUMNS + "=..."); System.exit(-1); } String seperator = conf.get(CommonConstants.SEPARATOR); if (seperator == null) { conf.set(CommonConstants.SEPARATOR, CommonConstants.DEFAULT_SEPARATOR); seperator = CommonConstants.DEFAULT_SEPARATOR; } // Make sure one or more columns are specified if (columns.split(",").length < 2) { usage("One or more columns in addition to the row key are required"); System.exit(-1); } //make sure tableName and columns are upper to used by phoenix. columns = columns.toUpperCase(); String tableName = otherArgs[0].toUpperCase(); String inputPath = otherArgs[1]; hbaseAdmin = new HBaseAdmin(conf); String tmpOutputPath = conf.get(CommonConstants.IMPORT_TMP_OUTPUT); conf.set(CommonConstants.TABLE_NAME, tableName); conf.set(CommonConstants.COLUMNS, columns); String hdfs_url = conf.get(CommonConstants.HDFS_URL); FileSystem fs = FileSystem.get(URI.create(hdfs_url), conf); FileStatus[] fileStatusArr = fs.listStatus(new Path(hdfs_url + inputPath)); if (fileStatusArr != null && fileStatusArr.length > 0) { TableConfiguration.getInstance().writeTableConfiguration(tableName, columns, seperator, conf); if (fileStatusArr[0].isFile()) { //?? boolean result = runJob(conf, tableName, inputPath, tmpOutputPath); if (result) { System.exit(0); } System.exit(-1); } for (FileStatus everyInputPath : fileStatusArr) { //?? Path inputPathStr = everyInputPath.getPath(); String absoluteInputPathStr = inputPath + "/" + inputPathStr.getName(); FileStatus[] subFileStatusArr = fs.listStatus(new Path(hdfs_url + absoluteInputPathStr)); if (subFileStatusArr == null || subFileStatusArr.length == 0)//?job continue; boolean ret = runJob(conf, tableName, absoluteInputPathStr, tmpOutputPath + "/" + inputPathStr.getName()); if (ret) { String base64Seperator = conf.get(CommonConstants.SEPARATOR); conf.set(CommonConstants.SEPARATOR, new String(Base64.decode(base64Seperator))); //?separator continue; } else // System.exit(-1); } } System.exit(0); // }
From source file:com.axiomine.largecollections.generator.GeneratorPrimitiveKeyKryoValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*w w w. j a v a 2 s. c o m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions //Package of your value serializer class. Use com.axiomine.bigcollections.functions String KPACKAGE = args[2]; //Class name (no packages) of the Key class Ex. String //Class name (no packages) of the value class Ex. Integer String K = args[3]; //Specify if you are using a KryoTemplate to generate your classes //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used //You can customize the name of the class generated String kCls = K; if (kCls.equals("byte[]")) { kCls = "BytesArray"; } String CLASS_NAME = kCls + "KryoV" + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/PrimitiveKeyKryoValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#K#", K); program = program.replaceAll("#KCLS#", kCls); program = program.replaceAll("#KPACKAGE#", KPACKAGE); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:com.axiomine.largecollections.generator.GeneratorKryoKPrimitiveValue.java
public static void main(String[] args) throws Exception { //Package of the new class you are generating Ex. com.mypackage String MY_PACKAGE = args[0];/*from w w w . j a v a2s . co m*/ //Any custom imports you need (: seperated). Use - if no custom imports are included //Ex. java.util.*:java.lang.Random String CUSTOM_IMPORTS = args[1].equals("-") ? "" : args[1]; //Package of your Key serializer class. Use com.axiomine.bigcollections.functions //Package of your value serializer class. Use com.axiomine.bigcollections.functions String VPACKAGE = args[2]; //Class name (no packages) of the Key class Ex. String //Class name (no packages) of the value class Ex. Integer String V = args[3]; //Specify if you are using a KryoTemplate to generate your classes //If true the template used to generate the class is KryoBasedMapTemplte, if false the JavaLangBasedMapTemplate is used //You can customize the name of the class generated String vCls = V; if (vCls.equals("byte[]")) { vCls = "BytesArray"; } String CLASS_NAME = "KryoK" + vCls + "Map"; //Default //String templatePath = args[5]; File root = new File(""); File outFile = new File(root.getAbsolutePath() + "/src/main/java/" + MY_PACKAGE.replaceAll("\\.", "/") + "/" + CLASS_NAME + ".java"); if (outFile.exists()) { System.out.println(outFile.getAbsolutePath() + " already exists. Please delete it and try again"); } { String[] imports = null; String importStr = ""; if (!StringUtils.isBlank(CUSTOM_IMPORTS)) { CUSTOM_IMPORTS.split(":"); for (String s : imports) { importStr = "import " + s + ";\n"; } } String program = FileUtils.readFileToString( new File(root.getAbsolutePath() + "/src/main/resources/KryoKeyPrimitiveValueMapTemplate.java")); program = program.replaceAll("#MY_PACKAGE#", MY_PACKAGE); program = program.replaceAll("#CUSTOM_IMPORTS#", importStr); program = program.replaceAll("#CLASS_NAME#", CLASS_NAME); program = program.replaceAll("#V#", V); program = program.replaceAll("#VPACKAGE#", VPACKAGE); program = program.replaceAll("#VCLS#", vCls); System.out.println(outFile.getAbsolutePath()); FileUtils.writeStringToFile(outFile, program); } }
From source file:org.ipinfodb.IpInfoDbClient.java
public static void main(String[] args) throws IOException { if (args.length < 3 || args.length > 4) { System.out.println("Usage: org.ipinfodb.IpInfoDbClient MODE API_KEY [IP_ADDRESS]\n" + "MODE can be either 'ip-country' or 'ip-city'.\n" + "If you don't have an API_KEY yet, you can get one for free by registering at http://www.ipinfodb.com/register.php."); return;/*from w w w .j a v a 2s. c o m*/ } //Code for Reading the multiple ip addresses from a given txt file. File inputLogFilePath = new File(args[1]); FileReader fr = new FileReader(inputLogFilePath); BufferedReader br = new BufferedReader(fr); String logLine; /*File outputFile=new File("C:/Users/Intelligrape/Desktop/New_Sample_29042014.txt"); // if file doesnt exists, then create it if (!outputFile.exists()) { outputFile.createNewFile(); } FileWriter fw = new FileWriter(outputFile,true); BufferedWriter bw = new BufferedWriter(fw); bw.write("S.no, IPAddress, Country, Region, City, Zipcode"); bw.newLine();*/ try { Class.forName("com.mysql.jdbc.Driver"); System.out.println("Driver found"); } catch (ClassNotFoundException e) { System.out.println("Driver not found: " + e); } String url_db = "jdbc:mysql://mysqldb.c7zitrf2gguq.us-east-1.rds.amazonaws.com/matse?user=shagun&password=shagun001"; Connection con = null; int insertCounter = 0; int count = 1; while ((logLine = br.readLine()) != null) { String mode = args[2]; String apiKey = args[3]; String url = "http://api.ipinfodb.com/v3/" + mode + "/?format=json&key=" + apiKey; String[] split = logLine.split(","); String ip = split[3]; url += "&ip=" + ip; try { HttpGet request = new HttpGet(url); HttpResponse response = HTTP_CLIENT.execute(request, new BasicHttpContext()); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new RuntimeException("IpInfoDb response is " + response.getStatusLine()); } String responseBody = EntityUtils.toString(response.getEntity()); IpCityResponse ipCityResponse = MAPPER.readValue(responseBody, IpCityResponse.class); if ("OK".equals(ipCityResponse.getStatusCode())) { //System.out.print(count+", "+ip+", "+ipCityResponse.getCountryCode() + ", " + ipCityResponse.getRegionName() + ", " + ipCityResponse.getCityName() + ", " + ipCityResponse.zipCode+ ", " + ipCityResponse.countryName + ", " + ipCityResponse.latitude + ", " + ipCityResponse.longitude + ", " + ipCityResponse.timeZone); //bw.write(count+", "+ip+", "+ipCityResponse.getCountryCode() + ", " + ipCityResponse.getRegionName() + ", " + ipCityResponse.getCityName() + ", " + ipCityResponse.zipCode + ", " + ipCityResponse.countryName + ", " + ipCityResponse.latitude + ", " + ipCityResponse.longitude + ", " + ipCityResponse.timeZone); try { con = DriverManager.getConnection(url_db); //System.out.println("Connected successfully"); Statement stmt = con.createStatement(); //System.out.println(logLine); //System.out.println(split.length); int result = stmt.executeUpdate("INSERT INTO LOGDATA1 VALUES('" + split[0] + "','" + split[1].trim() + "','" + split[2] + "','" + split[3] + "','" + split[4] + "','" + ipCityResponse.statusCode + "','" + ipCityResponse.countryCode + "','" + ipCityResponse.countryName + "','" + ipCityResponse.regionName + "','" + ipCityResponse.cityName + "','" + ipCityResponse.zipCode + "','" + ipCityResponse.latitude + "','" + ipCityResponse.longitude + "','" + ipCityResponse.timeZone + "')"); ++insertCounter; con.close(); System.out.println(insertCounter); } catch (SQLException e) { System.out.println("something wrong in the connection string: " + e); } } else { System.out.print("API status message is '" + ipCityResponse.getStatusMessage() + "'"); } } finally { //HTTP_CLIENT.getConnectionManager().shutdown(); } ++count; } HTTP_CLIENT.getConnectionManager().shutdown(); }