List of usage examples for java.io File isFile
public boolean isFile()
From source file:gobblin.compaction.hive.CompactionRunner.java
public static void main(String[] args) throws IOException, ConfigurationException { properties = CliOptions.parseArgs(MRCompactionRunner.class, args); File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR)); File[] listOfFiles = compactionConfigDir.listFiles(); if (listOfFiles == null || listOfFiles.length == 0) { System.err.println("No compaction configuration files found under " + compactionConfigDir); System.exit(1);/* w ww . j a v a 2 s. c o m*/ } int numOfJobs = 0; for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { numOfJobs++; } } LOG.info("Found " + numOfJobs + " compaction tasks."); try (PrintWriter pw = new PrintWriter(new OutputStreamWriter( new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)), Charset.forName("UTF-8")))) { for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath()); jobProperties = ConfigurationConverter.getProperties(jobConfig); long startTime = System.nanoTime(); compact(); long endTime = System.nanoTime(); long elapsedTime = endTime - startTime; double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime); pw.printf("%s: %f%n", file.getAbsolutePath(), seconds); } } } }
From source file:org.echocat.nodoodle.server.Main.java
public static void main(String[] args) { final File log4jConfig = new File(System.getProperty("log4j.configuration", "../config/log4j.xml")); if (log4jConfig.isFile()) { try {/*from www. j a v a 2s . c o m*/ final FileReader reader = new FileReader(log4jConfig); try { final DOMConfigurator domConfigurator = new DOMConfigurator(); domConfigurator.doConfigure(reader, getLoggerRepository()); } finally { IOUtils.closeQuietly(reader); } } catch (Exception e) { throw new RuntimeException("Could not configure log4j with " + log4jConfig + ".", e); } } final String applicationName = getApplicationName(); //System.setSecurityManager(new ServerSecurityManager()); LOG.info("Starting " + applicationName + "..."); final File config = new File( System.getProperty(Main.class.getPackage().getName() + ".config", "../config/nodoodleServer.xml")); final AbstractApplicationContext applicationContext = new FileSystemXmlApplicationContext(config.getPath()); LOG.info("Starting " + applicationName + "... DONE!"); Runtime.getRuntime().addShutdownHook(new Thread("destroyer") { @Override public void run() { LOG.info("Stopping " + applicationName + "..."); applicationContext.stop(); LOG.info("Stopping " + applicationName + "... DONE!"); } }); }
From source file:gobblin.compaction.CompactionRunner.java
public static void main(String[] args) throws ConfigurationException, IOException, SQLException { if (args.length != 1) { LOG.info("Proper usage: java -jar compaction.jar <global-config-file>\n" + "or\n" + "hadoop jar compaction.jar <global-config-file>\n" + "or\n" + "yarn jar compaction.jar <global-config-file>\n"); System.exit(1);//from www. j av a 2s. c o m } Configuration globalConfig = new PropertiesConfiguration(args[0]); properties = ConfigurationConverter.getProperties(globalConfig); File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR)); File[] listOfFiles = compactionConfigDir.listFiles(); if (listOfFiles == null || listOfFiles.length == 0) { System.err.println("No compaction configuration files found under " + compactionConfigDir); System.exit(1); } int numOfJobs = 0; for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { numOfJobs++; } } LOG.info("Found " + numOfJobs + " compaction tasks."); PrintWriter pw = new PrintWriter(new OutputStreamWriter( new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)), Charset.forName("UTF-8"))); for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath()); jobProperties = ConfigurationConverter.getProperties(jobConfig); long startTime = System.nanoTime(); compact(); long endTime = System.nanoTime(); long elapsedTime = endTime - startTime; double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime); pw.printf("%s: %f%n", file.getAbsolutePath(), seconds); } } pw.close(); }
From source file:com.tonygalati.sprites.SpriteGenerator.java
public static void main(String[] args) throws IOException { // if (args.length != 3) // {/*w w w . j a v a 2 s . c om*/ // System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n"); // System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n"); // System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n"); // System.out.print("most browsers.\n\n"); // return; // } // Integer margin = Integer.parseInt(args[1]); Integer margin = Integer.parseInt("1"); String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png"; SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator(); ClassLoader classLoader = SpriteGenerator.class.getClassLoader(); URL folderPath = classLoader.getResource(NAIC_SMALL_ICON); if (folderPath != null) { File imageFolder = new File(folderPath.getPath()); // Read images ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>(); Integer yCoordinate = null; for (File f : imageFolder.listFiles()) { if (f.isFile()) { String fileName = f.getName(); String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); if (ext.equals("png")) { System.out.println("adding file " + fileName); BufferedImage image = ImageIO.read(f); imageList.add(image); if (yCoordinate == null) { yCoordinate = 0; } else { yCoordinate += (image.getHeight() + margin); } // add to cssGenerator cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate); } } } // Find max width and total height int maxWidth = 0; int totalHeight = 0; for (BufferedImage image : imageList) { totalHeight += image.getHeight() + margin; if (image.getWidth() > maxWidth) maxWidth = image.getWidth(); } System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(), totalHeight, maxWidth); // Create the actual sprite BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); int currentY = 0; Graphics g = sprite.getGraphics(); for (BufferedImage image : imageList) { g.drawImage(image, 0, currentY, null); currentY += image.getHeight() + margin; } System.out.format("Writing sprite: %s%n", spriteFile); ImageIO.write(sprite, "png", new File(spriteFile)); File cssFile = cssGenerator.getFile(spriteFile); System.out.println(cssFile.getAbsolutePath() + " created"); } else { System.err.println("Could not find folder: " + NAIC_SMALL_ICON); } }
From source file:com.esri.geoportal.base.metadata.MetadataCLI.java
/** /* w ww .j av a 2 s . c o m*/ * <h1>run the javascript Evaluators.js scripts</h1> * from command line for testing. * * <div> java com.esri.geoportal.base.metadata.MetadataCLI -md={XMLFile_fullpath} *</div> * * <p><b>Note:</b> This only produces the basic JSON elements seen in the * elastic search json document. Other steps, such as itemID are found in {@link com.esri.geoportal.lib.elastic.request.PublishMetadataRequest#prePublish(ElasticContext, AccessUtil, AppResponse, MetadataDocument)} </p> * *<p><b>Note:</b> mainly tested in JetBrains Intellij</p> * <p><b>Note:</b> mvn command line call is in contrib</p> * * @author David Valentine * */ public static void main(String[] args) { Option help = Option.builder("h").required(false).longOpt("help").desc("HELP").build(); // Option metadataJsDir = // Option.builder("js") // .required(true) // .hasArg() // .longOpt("jsdir") // .desc("Base metadata javascript directory") // // .type(File.class) // test if this is a directory // .build(); ; /* not needed. js read from classpath, metadata/js/Evaluator.js required to be on classpath. TODO: test if this works in/on a jar, if not might need to test if running in a jar, and set appropriate resource location */ Option metadataFile = Option.builder("md").required(true).hasArg().longOpt("metdatafile") .desc("Metadata File") // .type(File.class) .build(); ; Option verbose = Option.builder("v").required(false) .longOpt("verboase").build(); ; Options options = new Options(); options.addOption(help); //options.addOption(metadataJsDir); options.addOption(metadataFile); ; options.addOption(verbose); ; // create the parser CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); Boolean v = line.hasOption("v"); String mds = line.getOptionValue("md"); File md = new File(mds); if (!md.isFile()) System.err.println("Md Metadata must be a file"); testScriptEvaluator(md, v); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } catch (Exception ex) { System.err.println("Metadata Evaluation Failed. Reason: " + ex.getMessage()); } }
From source file:com.jff.searchapicluster.server.mina.Server.java
public static void main(String[] args) throws Throwable { org.apache.commons.configuration.Configuration config = new PropertiesConfiguration("settings.txt"); int serverPort = config.getInt("listenPort"); NioSocketAcceptor acceptor = new NioSocketAcceptor(); acceptor.getFilterChain().addLast("com/jff/searchapicluster/core/mina/codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); acceptor.getFilterChain().addLast("logger", new LoggingFilter()); acceptor.setHandler(new ServerSessionHandler()); acceptor.bind(new InetSocketAddress(serverPort)); System.out.println("Listening on port " + serverPort); System.out.println("Please enter filename"); // open up standard input BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { String filepath = br.readLine(); filepath = "/Users/admin/repos/study_repos/kurs_sp/search_api_cluster/SearchApiClusterServer/task.json"; File file = new File(filepath); Logger.d(LOG_TAG, file.getAbsolutePath()); if (file.exists() && file.isFile()) { Gson gson = new Gson(); SearchTask taskMessage = gson.fromJson(new FileReader(file), SearchTask.class); ServerManager serverManager = ServerManager.getInstance(); Logger.d(LOG_TAG, taskMessage.toString()); serverManager.startProcessTask(taskMessage); } else {//from ww w.ja v a 2 s. com Logger.d(LOG_TAG, filepath + "not found"); } } }
From source file:sample.fa.ScriptRunnerApplication.java
public static void main(String[] args) { SwingUtilities.invokeLater(() -> { ScriptRunnerApplication app = new ScriptRunnerApplication(); app.createGUI();/*w w w . j a v a 2s. c o m*/ if (args.length > 0) { File f = new File(args[0]); if (f.isFile()) { app.loadScript(f); } } }); }
From source file:GuaranteeAFile.java
public static void main(String[] args) { String filename = "C:/myFile.txt"; File aFile = new File(filename); if (aFile.isDirectory()) { System.out.println("The path " + aFile.getPath() + " does not specify a file. Program aborted."); System.exit(1);/*from ww w . j a v a2 s . c o m*/ } if (!aFile.isFile()) { aFile = aFile.getAbsoluteFile(); File parentDir = new File(aFile.getParent()); if (!parentDir.exists()) { parentDir.mkdirs(); } } FileOutputStream outputFile = null; try { outputFile = new FileOutputStream(aFile, true); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } }
From source file:de.oth.keycloak.InitKeycloakServer.java
public static void main(String[] args) { CheckParams checkParams = CheckParams.create(args, System.out, InitKeycloakServer.class.getName()); if (checkParams == null) { System.exit(1);// w w w.j av a2 s .c om } try { String server = checkParams.getServer(); String realm = checkParams.getRealm(); String user = checkParams.getUser(); String pwd = checkParams.getPwd(); String clientStr = checkParams.getClient(); String secret = checkParams.getSecret(); String initFileStr = checkParams.getInitFile(); File initFile = new File(initFileStr); if (!initFile.isFile()) { URL url = InitKeycloakServer.class.getClassLoader().getResource(initFileStr); if (url != null) { initFile = new File(url.getFile()); if (!initFile.isFile()) { log.error("init file does not exist: " + initFile); System.exit(1); } } else { log.error("init file does not exist: " + initFile); System.exit(1); } } Keycloak keycloak = (secret == null) ? Keycloak.getInstance(server, realm, user, pwd, clientStr) : Keycloak.getInstance(server, realm, user, pwd, clientStr, secret); ObjectMapper mapper = new ObjectMapper(); RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class); if (realmsConfig != null) { List<RealmConfig> realmList = realmsConfig.getRealms(); if (realmList == null || realmList.isEmpty()) { log.error("no realms config found 1"); return; } for (RealmConfig realmConf : realmList) { addRealm(keycloak, realmConf); } } else { log.error("no realms config found 2"); } } catch (Exception e) { log.error(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); System.exit(1); } }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.DbpediaCategoryAttributeCounts.java
public static void main(String args[]) throws FileNotFoundException, IOException { stopAttributes.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); stopAttributes.add("http://www.w3.org/2002/07/owl#sameAs"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageRevisionID"); stopAttributes.add("http://dbpedia.org/ontology/wikiPageID"); stopAttributes.add("http://purl.org/dc/elements/1.1/description"); stopAttributes.add("http://dbpedia.org/ontology/thumbnail"); //stopAttributes.add("http://dbpedia.org/ontology/type"); String path = DBpediaOntology.DBPEDIA_CSV_FOLDER; if (args != null && args.length > 0) { path = args[0];/*from w w w .j a va 2 s. c o m*/ if (!path.endsWith("/")) { path = path + "/"; } } File folder = new File(path); if (!folder.exists()) { System.out.println("The path with DBpedia CSV files is set as " + path); System.out.println("You need to change the path with the correct one on your PC"); System.exit(0); } for (File f : new File(path).listFiles()) { if (f.isFile() && f.getName().endsWith(".csv.gz")) { System.out.println("Processing file " + f.getName() + "..."); processFile(f, f.getName().replaceAll("\\.csv.gz", "")); } } System.out.println(entities.size() + " entities processed"); System.out.println(categories.size() + " categories found"); System.out.println(attributes.size() + " attributes found"); try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path + "counts.bin"))) { oos.writeObject(categories); oos.writeObject(attributes); oos.writeObject(categoryCount); oos.writeObject(attributeCount); oos.writeObject(categoryAttributeCount); oos.writeObject(attributeCategoryCount); } }