List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
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 w w w . ja va 2 s . 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 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: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];/* w w w .j av a 2 s.c om*/ //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.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];//w w w. j av a 2s . c om //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: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 ww . ja va2 s . com*/ //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.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 a v a 2s . c om*/ //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.gagein.crawler.Extractor.java
public static void main(String[] args) { String website = "http://www.gagein.com"; String tempName = "temp"; // ???//from w w w .ja v a 2s . c om String dirPath = System.getProperty("user.dir") + File.separator + tempName + File.separator + website.substring(7).split("\\.")[1];// remove http://; Extractor ex = new Extractor(); ex.getFilesPath(dirPath); System.out.println(ex.pathSet); ArticleStripper as = new ArticleStripper(); as.setExtractAuthor(false); as.setExtractContent(true); as.setExtractDate(false); as.setExtractImg(false); as.setKeepContentLink(false); for (String url : ex.pathSet) { System.out.println(url); File file = new File(url); try { String page = FileUtils.readFileToString(file); System.out.println("Contents of file: " + page); logger.debug("==============?" + url + "?"); Article article = as.retrieveArticle(null, null, page, null); System.out.println("##################" + article.getContent()); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.netflix.suro.SuroServer.java
public static void main(String[] args) throws IOException { final AtomicReference<Injector> injector = new AtomicReference<Injector>(); try {//ww w. j av a 2 s . co m // Parse the command line Options options = createOptions(); final CommandLine line = new BasicParser().parse(options, args); // Load the properties file final Properties properties = new Properties(); if (line.hasOption('p')) { properties.load(new FileInputStream(line.getOptionValue('p'))); } // Bind all command line options to the properties with prefix "SuroServer." for (Option opt : line.getOptions()) { String name = opt.getOpt(); String value = line.getOptionValue(name); String propName = PROP_PREFIX + opt.getArgName(); if (propName.equals(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY)) { properties.setProperty(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertySinkConfigurator.SINK_PROPERTY)) { properties.setProperty(DynamicPropertySinkConfigurator.SINK_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY)) { properties.setProperty(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY, FileUtils.readFileToString(new File(value))); } else { properties.setProperty(propName, value); } } create(injector, properties); injector.get().getInstance(LifecycleManager.class).start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } catch (IOException e) { // do nothing because Closeables.close will swallow IOException } } }); waitForShutdown(getControlPort(properties)); } catch (Throwable e) { System.err.println("SuroServer startup failed: " + e.getMessage()); System.exit(-1); } finally { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } }
From source file:com.edgenius.wiki.ext.textnut.NutParser.java
public static void main(String[] args) throws IOException { NutParser parser = new NutParser(); // parser.parseHTML(FileUtils.readFileToString(new File("c:/temp/a.html"))); Map<String, File> map = parser.parseBPlist( new FileInputStream(new File("C:/Dapeng/Future/webarchive/TextNut.nut/20110312/P1.webarchive"))); if (map != null) { for (Entry<String, File> entry : map.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); }//from w w w . j a v a 2 s . c om File file = map.get(MAIN_RESOURCE_URL); String content = parser.convertNutHTMLToPageHTML(FileUtils.readFileToString(file)); System.out.println("======="); System.out.println(content); System.out.println("======="); } }
From source file:mvm.rya.indexing.external.ExternalIndexMain.java
public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 6, "java " + ExternalIndexMain.class.getCanonicalName() + " sparqlFile cbinstance cbzk cbuser cbpassword rdfTablePrefix."); final String sparqlFile = args[0]; instStr = args[1];/*from w w w . j a va 2 s. c om*/ zooStr = args[2]; userStr = args[3]; passStr = args[4]; tablePrefix = args[5]; String queryString = FileUtils.readFileToString(new File(sparqlFile)); // Look for Extra Indexes Instance inst = new ZooKeeperInstance(instStr, zooStr); Connector c = inst.getConnector(userStr, passStr.getBytes()); System.out.println("Searching for Indexes"); Map<String, String> indexTables = Maps.newLinkedHashMap(); for (String table : c.tableOperations().list()) { if (table.startsWith(tablePrefix + "INDEX_")) { Scanner s = c.createScanner(table, new Authorizations()); s.setRange(Range.exact(new Text("~SPARQL"))); for (Entry<Key, Value> e : s) { indexTables.put(table, e.getValue().toString()); } } } List<ExternalTupleSet> index = Lists.newArrayList(); if (indexTables.isEmpty()) { System.out.println("No Index found"); } else { for (String table : indexTables.keySet()) { String indexSparqlString = indexTables.get(table); System.out.println("====================== INDEX FOUND ======================"); System.out.println(" table : " + table); System.out.println(" sparql : "); System.out.println(indexSparqlString); index.add(new AccumuloIndexSet(indexSparqlString, c, table)); } } // Connect to Rya Sail s = getRyaSail(); SailRepository repo = new SailRepository(s); repo.initialize(); // Perform Query CountingTupleQueryResultHandler count = new CountingTupleQueryResultHandler(); SailRepositoryConnection conn; if (index.isEmpty()) { conn = repo.getConnection(); } else { ExternalProcessor processor = new ExternalProcessor(index); Sail processingSail = new ExternalSail(s, processor); SailRepository smartSailRepo = new SailRepository(processingSail); smartSailRepo.initialize(); conn = smartSailRepo.getConnection(); } startTime = System.currentTimeMillis(); lastTime = startTime; System.out.println("Query Started"); conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(count); System.out.println("Count of Results found : " + count.i); System.out.println("Total query time (s) : " + (System.currentTimeMillis() - startTime) / 1000.); }
From source file:com.haulmont.yarg.console.ConsoleRunner.java
public static void main(String[] args) { Options options = createOptions();/*w w w .j a v a 2 s . c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (!cmd.hasOption(REPORT_PATH) || !cmd.hasOption(OUTPUT_PATH)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("report", options); System.exit(-1); } String templateCode = cmd.getOptionValue(TEMPLATE_CODE, ReportTemplate.DEFAULT_TEMPLATE_CODE); PropertiesLoader propertiesLoader = new DefaultPropertiesLoader( cmd.getOptionValue(PROPERTIES_PATH, DefaultPropertiesLoader.DEFAULT_PROPERTIES_PATH)); Reporting reporting = createReportingEngine(propertiesLoader); XmlReader xmlReader = new DefaultXmlReader(); Report report = xmlReader .parseXml(FileUtils.readFileToString(new File(cmd.getOptionValue(REPORT_PATH)))); Map<String, Object> params = parseReportParams(cmd, report); reporting.runReport(new RunParams(report).templateCode(templateCode).params(params), new FileOutputStream(cmd.getOptionValue(OUTPUT_PATH))); if (doExitWhenFinished) { System.exit(0); } } catch (Exception e) { e.printStackTrace(); if (doExitWhenFinished) { System.exit(-1); } } }