List of usage examples for java.io File exists
public boolean exists()
From source file:PinotResponseTime.java
public static void main(String[] args) throws Exception { try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost post = new HttpPost("http://localhost:8099/query"); CloseableHttpResponse res;/*from w ww.j ava2 s. c om*/ if (STORE_RESULT) { File dir = new File(RESULT_DIR); if (!dir.exists()) { dir.mkdirs(); } } int length; // Make sure all segments online System.out.println("Test if number of records is " + RECORD_NUMBER); post.setEntity(new StringEntity("{\"pql\":\"select count(*) from tpch_lineitem\"}")); while (true) { System.out.print('*'); res = client.execute(post); boolean valid; try (BufferedInputStream in = new BufferedInputStream(res.getEntity().getContent())) { length = in.read(BUFFER); valid = new String(BUFFER, 0, length, "UTF-8").contains("\"value\":\"" + RECORD_NUMBER + "\""); } res.close(); if (valid) { break; } else { Thread.sleep(5000); } } System.out.println("Number of Records Test Passed"); // Start Benchmark for (int i = 0; i < QUERIES.length; i++) { System.out.println( "--------------------------------------------------------------------------------"); System.out.println("Start running query: " + QUERIES[i]); post.setEntity(new StringEntity("{\"pql\":\"" + QUERIES[i] + "\"}")); // Warm-up Rounds System.out.println("Run " + WARMUP_ROUND + " times to warm up cache..."); for (int j = 0; j < WARMUP_ROUND; j++) { res = client.execute(post); if (!isValid(res, null)) { System.out.println("\nInvalid Response, Sleep 20 Seconds..."); Thread.sleep(20000); } res.close(); System.out.print('*'); } System.out.println(); // Test Rounds int[] time = new int[TEST_ROUND]; int totalTime = 0; int validIdx = 0; System.out.println("Run " + TEST_ROUND + " times to get average time..."); while (validIdx < TEST_ROUND) { long startTime = System.currentTimeMillis(); res = client.execute(post); long endTime = System.currentTimeMillis(); boolean valid; if (STORE_RESULT && validIdx == 0) { valid = isValid(res, RESULT_DIR + File.separator + i + ".json"); } else { valid = isValid(res, null); } if (!valid) { System.out.println("\nInvalid Response, Sleep 20 Seconds..."); Thread.sleep(20000); res.close(); continue; } res.close(); time[validIdx] = (int) (endTime - startTime); totalTime += time[validIdx]; System.out.print(time[validIdx] + "ms "); validIdx++; } System.out.println(); // Process Results double avgTime = (double) totalTime / TEST_ROUND; double stdDev = 0; for (int temp : time) { stdDev += (temp - avgTime) * (temp - avgTime) / TEST_ROUND; } stdDev = Math.sqrt(stdDev); System.out.println("The average response time for the query is: " + avgTime + "ms"); System.out.println("The standard deviation is: " + stdDev); } } }
From source file:de.tudarmstadt.ukp.argumentation.data.roomfordebate.DataFetcher.java
public static void main(String[] args) throws Exception { File crawledPagesFolder = new File(args[0]); if (!crawledPagesFolder.exists()) { crawledPagesFolder.mkdirs();//w w w . j av a 2 s . c o m } File outputFolder = new File(args[1]); if (!outputFolder.exists()) { outputFolder.mkdirs(); } // read links from text file final String urlsResourceName = "roomfordebate-urls.txt"; InputStream urlsStream = DataFetcher.class.getClassLoader().getResourceAsStream(urlsResourceName); if (urlsStream == null) { throw new IOException("Cannot find resource " + urlsResourceName + " on the classpath"); } // read list of urls List<String> urls = new ArrayList<>(); LineIterator iterator = IOUtils.lineIterator(urlsStream, "utf-8"); while (iterator.hasNext()) { // ignore commented url (line starts with #) String line = iterator.nextLine(); if (!line.startsWith("#") && !line.trim().isEmpty()) { urls.add(line.trim()); } } // download all crawlPages(urls, crawledPagesFolder); List<File> files = new ArrayList<>(FileUtils.listFiles(crawledPagesFolder, null, false)); Collections.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); int idCounter = 0; for (File file : files) { NYTimesCommentsScraper commentsScraper = new NYTimesCommentsScraper(); NYTimesArticleExtractor extractor = new NYTimesArticleExtractor(); String html = FileUtils.readFileToString(file, "utf-8"); idCounter++; File outputFileArticle = new File(outputFolder, String.format("Cx%03d.txt", idCounter)); File outputFileComments = new File(outputFolder, String.format("Dx%03d.txt", idCounter)); try { List<Comment> comments = commentsScraper.extractComments(html); Article article = extractor.extractArticle(html); saveArticleToText(article, outputFileArticle); System.out.println("Saved to " + outputFileArticle); saveCommentsToText(comments, outputFileComments, article); System.out.println("Saved to " + outputFileComments); } catch (IOException ex) { System.err.println(file.getName() + "\n" + ex.getMessage()); } } }
From source file:accumulo.AccumuloStuff.java
public static void main(String[] args) throws Exception { File tmp = new File(System.getProperty("user.dir") + "/target/mac-test"); if (tmp.exists()) { FileUtils.deleteDirectory(tmp);/*from ww w . j av a 2 s.c o m*/ } tmp.mkdirs(); String passwd = "password"; MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(tmp, passwd); cfg.setNumTservers(1); // cfg.useMiniDFS(true); final MiniAccumuloClusterImpl cluster = cfg.build(); setCoreSite(cluster); cluster.start(); ExecutorService svc = Executors.newFixedThreadPool(2); try { Connector conn = cluster.getConnector("root", passwd); String table = "table"; conn.tableOperations().create(table); final BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig()); final AtomicBoolean flushed = new AtomicBoolean(false); Runnable writer = new Runnable() { @Override public void run() { try { Mutation m = new Mutation("row"); m.put("colf", "colq", "value"); bw.addMutation(m); bw.flush(); flushed.set(true); } catch (Exception e) { log.error("Got exception trying to flush mutation", e); } log.info("Exiting batchwriter thread"); } }; Runnable restarter = new Runnable() { @Override public void run() { try { for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) { cluster.killProcess(ServerType.TABLET_SERVER, proc); } cluster.exec(TabletServer.class); } catch (Exception e) { log.error("Caught exception restarting tabletserver", e); } log.info("Exiting restart thread"); } }; svc.execute(writer); svc.execute(restarter); log.info("Waiting for shutdown"); svc.shutdown(); if (!svc.awaitTermination(120, TimeUnit.SECONDS)) { log.info("Timeout on shutdown exceeded"); svc.shutdownNow(); } else { log.info("Cleanly shutdown"); log.info("Threadpool is terminated? " + svc.isTerminated()); } if (flushed.get()) { log.info("****** BatchWriter was flushed *********"); } else { log.info("****** BatchWriter was NOT flushed *********"); } bw.close(); log.info("Got record {}", Iterables.getOnlyElement(conn.createScanner(table, Authorizations.EMPTY))); } finally { cluster.stop(); } }
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 2s . 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/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 ww w .j a 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/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];//www. j a va2 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/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:grnet.validation.XMLValidation.java
public static void main(String[] args) throws IOException { // TODO Auto-generated method ssstub Enviroment enviroment = new Enviroment(args[0]); if (enviroment.envCreation) { String schemaUrl = enviroment.getArguments().getSchemaURL(); Core core = new Core(schemaUrl); XMLSource source = new XMLSource(args[0]); File sourceFile = source.getSource(); if (sourceFile.exists()) { Collection<File> xmls = source.getXMLs(); System.out.println("Validating repository:" + sourceFile.getName()); System.out.println("Number of files to validate:" + xmls.size()); Iterator<File> iterator = xmls.iterator(); System.out.println("Validating against schema:" + schemaUrl + "..."); ValidationReport report = null; if (enviroment.getArguments().createReport().equalsIgnoreCase("true")) { report = new ValidationReport(enviroment.getArguments().getDestFolderLocation(), enviroment.getDataProviderValid().getName()); }//from w ww . j a va 2 s . c o m ConnectionFactory factory = new ConnectionFactory(); factory.setHost(enviroment.getArguments().getQueueHost()); factory.setUsername(enviroment.getArguments().getQueueUserName()); factory.setPassword(enviroment.getArguments().getQueuePassword()); while (iterator.hasNext()) { StringBuffer logString = new StringBuffer(); logString.append(sourceFile.getName()); logString.append(" " + schemaUrl); File xmlFile = iterator.next(); String name = xmlFile.getName(); name = name.substring(0, name.indexOf(".xml")); logString.append(" " + name); boolean xmlIsValid = core.validateXMLSchema(xmlFile); if (xmlIsValid) { logString.append(" " + "Valid"); slf4jLogger.info(logString.toString()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes()); channel.close(); connection.close(); try { if (report != null) { report.raiseValidFilesNum(); } FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderValid()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { logString.append(" " + "Invalid"); slf4jLogger.info(logString.toString()); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes()); channel.close(); connection.close(); try { if (report != null) { if (enviroment.getArguments().extendedReport().equalsIgnoreCase("true")) report.appendXMLFileNameNStatus(xmlFile.getPath(), Constants.invalidData, core.getReason()); report.raiseInvalidFilesNum(); } FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderInValid()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (report != null) { report.writeErrorBank(core.getErrorBank()); report.appendGeneralInfo(); } System.out.println("Validation is done."); } } }
From source file:D20140128.ApacheXMLGraphicsTest.EPSExample1.java
/** * Command-line interface/*from w ww . j av a 2 s . com*/ * * @param args command-line arguments */ public static void main(String[] args) { try { File targetDir; if (args.length >= 1) { targetDir = new File(args[0]); } else { targetDir = new File("."); } if (!targetDir.exists()) { System.err.println("Target Directory does not exist: " + targetDir); } generateEPSusingJava2D(new File(targetDir, "eps-example1.eps")); } catch (Exception e) { e.printStackTrace(); } }
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];// 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 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.nohowdezign.gcpmanager.Main.java
public final static void main(String[] args) { //Remove old log, it does not need to be there anymore. File oldLog = new File("./CloudPrintManager.log"); if (oldLog.exists()) { oldLog.delete();// w w w . j av a2 s . c o m } //Create a file reader for the props file Reader propsStream = null; try { propsStream = new FileReader("./props.json"); } catch (FileNotFoundException e1) { e1.printStackTrace(); } PrintManagerProperties props = null; if (propsStream != null) { props = gson.fromJson(propsStream, PrintManagerProperties.class); } else { logger.error("Property file does not exist. Please create one."); } //Set the variables to what is in the props file String email = props.getEmail(); String password = props.getPassword(); String printerId = props.getPrinterId(); amountOfPagesPerPrintJob = props.getAmountOfPagesPerPrintJob(); timeRestraintsForPrinter = props.getTimeRestraintsForPrinter(); JobStorageManager.timeToKeepFileInDays = props.getTimeToKeepFileInDays(); //AuthenticationManager authenticationManager = new AuthenticationManager(); //authenticationManager.setPasswordToUse(props.getAdministrativePassword()); //authenticationManager.initialize(1337); //Start the authentication manager on port 1337 try { cloudPrint.connect(email, password, "cloudprintmanager-1.0"); } catch (CloudPrintAuthenticationException e) { logger.error(e.getMessage()); } //TODO: Get a working website ready //Thread adminConsole = new Thread(new HttpServer(80), "HttpServer"); //adminConsole.start(); Thread printJobManager = new Thread(new JobStorageManagerThread(), "JobStorageManager"); printJobManager.start(); try { if (System.getProperty("os.name").toLowerCase().startsWith("win")) { logger.error("Your operating system is not supported. Please switch to linux ya noob."); System.exit(1); } else { PrinterManager printerManager = new PrinterManager(cloudPrint); File cupsPrinterDir = new File("/etc/cups/ppd"); if (cupsPrinterDir.isDirectory() && cupsPrinterDir.canRead()) { for (File cupsPrinterPPD : cupsPrinterDir.listFiles()) { //Init all of the CUPS printers in the manager printerManager.initializePrinter(cupsPrinterPPD, cupsPrinterPPD.getName()); } } else { logger.error("Please run this with a higher access level."); System.exit(1); } } } catch (Exception e) { e.printStackTrace(); } while (true) { try { getPrintingJobs(printerId); } catch (Exception e) { e.printStackTrace(); } } }