List of usage examples for java.io File getAbsolutePath
public String getAbsolutePath()
From source file:com.act.biointerpretation.desalting.ChemicalDesalter.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from w w w. jav a 2 s . c o m } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionDesalter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } ChemicalDesalter runner = new ChemicalDesalter(); String outAnalysis = cl.getOptionValue(OPTION_OUTPUT_PREFIX); if (cl.hasOption(OPTION_INCHI_INPUT_LIST)) { File inputFile = new File(cl.getOptionValue(OPTION_INCHI_INPUT_LIST)); if (!inputFile.exists()) { System.err.format("Cannot find input file at %s\n", inputFile.getAbsolutePath()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } runner.exampleChemicalsList(outAnalysis, inputFile); } }
From source file:Main.java
/** Index all text files under a directory. */ public static void main(String[] args) { String usage = "java IndexFiles" + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n" + "This indexes the documents in DOCS_PATH, creating a Lucene index" + "in INDEX_PATH that can be searched with SearchFiles"; String indexPath = "index"; String docsPath = null;//from www. j a v a 2 s .c o m boolean create = true; for (int i = 0; i < args.length; i++) { if ("-index".equals(args[i])) { indexPath = args[i + 1]; i++; } else if ("-docs".equals(args[i])) { docsPath = args[i + 1]; i++; } else if ("-update".equals(args[i])) { create = false; } } if (docsPath == null) { System.err.println("Usage: " + usage); System.exit(1); } final File docDir = new File(docsPath); if (!docDir.exists() || !docDir.canRead()) { System.out.println("Document directory '" + docDir.getAbsolutePath() + "' does not exist or is not readable, please check the path"); System.exit(1); } Date start = new Date(); try { System.out.println("Indexing to directory '" + indexPath + "'..."); Directory dir = FSDirectory.open(new File(indexPath)); // :Post-Release-Update-Version.LUCENE_XY: Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_0, analyzer); if (create) { // Create a new index in the directory, removing any // previously indexed documents: iwc.setOpenMode(OpenMode.CREATE); } else { // Add new documents to an existing index: iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); } // Optional: for better indexing performance, if you // are indexing many documents, increase the RAM // buffer. But if you do this, increase the max heap // size to the JVM (eg add -Xmx512m or -Xmx1g): // // iwc.setRAMBufferSizeMB(256.0); IndexWriter writer = new IndexWriter(dir, iwc); indexDocs(writer, docDir); // NOTE: if you want to maximize search performance, // you can optionally call forceMerge here. This can be // a terribly costly operation, so generally it's only // worth it when your index is relatively static (ie // you're done adding documents to it): // // writer.forceMerge(1); writer.close(); Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); } catch (IOException e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } }
From source file:azkaban.migration.schedule2trigger.Schedule2Trigger.java
public static void main(String[] args) throws Exception { if (args.length < 1) { printUsage();//w w w.ja v a2 s.co m } File confFile = new File(args[0]); try { logger.info("Trying to load config from " + confFile.getAbsolutePath()); props = loadAzkabanConfig(confFile); } catch (Exception e) { e.printStackTrace(); logger.error(e); return; } try { outputDir = File.createTempFile("schedules", null); logger.info("Creating temp dir for dumping existing schedules."); outputDir.delete(); outputDir.mkdir(); } catch (Exception e) { e.printStackTrace(); logger.error(e); return; } try { schedule2File(); } catch (Exception e) { e.printStackTrace(); logger.error(e); return; } try { file2ScheduleTrigger(); } catch (Exception e) { e.printStackTrace(); logger.error(e); return; } logger.info("Uploaded all schedules. Removing temp dir."); FileUtils.deleteDirectory(outputDir); System.exit(0); }
From source file:com.moss.appkeep.server.AppkeepServer.java
public static void main(String[] args) throws Exception { System.setProperty("org.mortbay.log.class", Slf4jLog.class.getName()); File log4jConfigFile = new File("log4j.xml"); if (log4jConfigFile.exists()) { DOMConfigurator.configureAndWatch(log4jConfigFile.getAbsolutePath(), 1000); } else {/* w w w.ja va2 s.c o m*/ BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.INFO); } ServerConfiguration config; JAXBContext context = JAXBContext.newInstance(ServerConfiguration.class, VeracityId.class, SimpleId.class, PasswordProofRecipie.class, ProofDelegationRecipie.class); JAXBHelper helper = new JAXBHelper(context); Logger log = Logger.getLogger(AppkeepServer.class); File configFile = new File("settings.xml"); if (!configFile.exists()) configFile = new File(new File(System.getProperty("user.dir")), ".appkeep-server.xml"); if (!configFile.exists()) configFile = new File("/etc/appkeep-server.xml"); if (!configFile.exists()) { config = new ServerConfiguration(); helper.writeToFile(helper.writeToXmlString(config), configFile); log.warn("Created default config file at " + configFile.getAbsolutePath()); } else { log.info("Reading configuration from " + configFile.getAbsolutePath()); config = helper.readFromFile(configFile); } ProxyFactory proxyFactory = new ProxyFactory(new HessianProxyProvider()); try { new AppkeepServer(config, proxyFactory); } catch (Exception e) { e.printStackTrace(); System.out.println("Unexpected Error. Shutting Down."); System.exit(1); } }
From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java
/** * Merge a xml file with Velocity template. The third parameter is the properties file, where the * key/value is added to the velocity context. The fourth parameter is the output file. If not * included, the result is printed to system.out. * /*from w w w .ja v a 2 s. c o m*/ * @param args are file.xml template.vm properties.prop [output.file] * @throws JDOMException if the xml file couldn't be parsed * @throws IOException couldn't find one of the files */ public static void main(String[] args) throws JDOMException, IOException { if (args.length < 3) { System.out.println( "Missing input files. XMLToVelocity file.xml template.vm prop.properties [output.file]"); return; } final Properties properties = new Properties(); final File prop = new File(args[2]); if (prop.exists()) properties.load(new FileReader(prop)); else throw new IOException("Couldn't find the property file:" + prop.getAbsolutePath()); final MergeXMLWithVelocity xtv = new MergeXMLWithVelocity(properties); xtv.create(args); }
From source file:edu.cuhk.hccl.IDConverter.java
public static void main(String[] args) { if (args.length < 2) { printUsage();//from w w w . j ava 2s .c o m } try { File inFile = new File(args[0]); File outFile = new File(args[1]); if (inFile.isDirectory()) { System.out.println("ID Converting begins..."); FileUtils.forceMkdir(outFile); for (File file : inFile.listFiles()) { if (!file.isHidden()) processFile(file, new File(outFile.getAbsolutePath() + "/" + FilenameUtils.removeExtension(file.getName()) + "-long.txt")); } } else if (inFile.isFile()) { System.out.println("ID Converting begins..."); processFile(inFile, outFile); } else { printUsage(); } System.out.println("ID Converting finished."); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.appunity.ant.util.NewClass.java
public static void main(String[] args) throws FileNotFoundException, IOException { Collection<File> listFiles = FileUtils.listFiles(srcDir, new String[] { "java" }, true); int size = 0; System.out.println("listFiles = " + listFiles.size()); for (final File file : listFiles) { CharsetDetector charsetDetector = new CharsetDetector(); String[] detectAllCharset = charsetDetector.detectCharset(file); if (detectAllCharset != null && detectAllCharset.length == 1 && "GB2312".equals(detectAllCharset[0])) { System.out.println(Arrays.toString(detectAllCharset) + file.getAbsolutePath()); } else {// ww w . j av a 2 s.c om System.out.println(Arrays.toString(detectAllCharset) + file.getAbsolutePath()); } } }
From source file:com.versusoft.packages.jodl.gui.CommandLineGUI.java
public static void main(String args[]) throws SAXException, IOException { Handler fh = new FileHandler(LOG_FILENAME_PATTERN); fh.setFormatter(new SimpleFormatter()); //removeAllLoggersHandlers(Logger.getLogger("")); Logger.getLogger("").addHandler(fh); Logger.getLogger("").setLevel(Level.FINEST); Options options = new Options(); Option option1 = new Option("in", "ODT file (required)"); option1.setRequired(true);// ww w .j a va2 s .c o m option1.setArgs(1); Option option2 = new Option("out", "Output file (required)"); option2.setRequired(false); option2.setArgs(1); Option option3 = new Option("pic", "extract pics"); option3.setRequired(false); option3.setArgs(1); Option option4 = new Option("page", "enable pagination processing"); option4.setRequired(false); option4.setArgs(0); options.addOption(option1); options.addOption(option2); options.addOption(option3); options.addOption(option4); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { printHelp(); return; } if (cmd.hasOption("help")) { printHelp(); return; } File outFile = new File(cmd.getOptionValue("out")); OdtUtils utils = new OdtUtils(); utils.open(cmd.getOptionValue("in")); //utils.correctionStep(); utils.saveXML(outFile.getAbsolutePath()); try { if (cmd.hasOption("page")) { OdtUtils.paginationProcessing(outFile.getAbsolutePath()); } OdtUtils.correctionProcessing(outFile.getAbsolutePath()); } catch (ParserConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (SAXException ex) { logger.log(Level.SEVERE, null, ex); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerException ex) { logger.log(Level.SEVERE, null, ex); } if (cmd.hasOption("pic")) { String imageDir = cmd.getOptionValue("pic"); if (!imageDir.endsWith("/")) { imageDir += "/"; } try { String basedir = new File(cmd.getOptionValue("out")).getParent().toString() + System.getProperty("file.separator"); OdtUtils.extractAndNormalizeEmbedPictures(cmd.getOptionValue("out"), cmd.getOptionValue("in"), basedir, imageDir); } catch (SAXException ex) { logger.log(Level.SEVERE, null, ex); } catch (ParserConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerException ex) { logger.log(Level.SEVERE, null, ex); } } }
From source file:io.fluo.quickstart.Main.java
public static void main(String[] args) throws Exception { File miniAccumuloDir = Files.createTempDir(); FluoConfiguration config = new FluoConfiguration(); config.addObserver(new ObserverConfiguration(DocumentObserver.class.getName())); config.setApplicationName("quick-start"); config.setMiniDataDir(miniAccumuloDir.getAbsolutePath()); System.out.println("\nStarting Mini ..."); // Use try with resources to ensure that FluoClient is closed. try (MiniFluo mini = FluoFactory.newMiniFluo(config); FluoClient fluoClient = FluoFactory.newClient(mini.getClientConfiguration())) { // TODO could use a LoaderExecutor to load documents using multiple // threads. Left as an exercise to reader. System.out.println("Adding documents ..."); addDocument(fluoClient, "00001", "hello world welcome to the fluo quickstart the first one in the entire world"); addDocument(fluoClient, "00001", "hola world welcome to the fluo quickstart the first one in the entire world"); addDocument(fluoClient, "00002", "hola world"); System.out.println("Reading documents ..."); printDocument(fluoClient, "00001"); printDocument(fluoClient, "00002"); System.out.println();// ww w . j a va 2 s . c o m System.out.println("Waiting for observer ..."); // wait for observer to run and update counts mini.waitForObservers(); System.out.println("Printing word counts..."); printWordCounts(fluoClient); // TODO : Add ability to delete document and decrement counts, left as an // exercise for reader. Suggest adding a column which indicates a documents // should be deleted by observer. For bonus points, handle the case where // document not yet processed by observer is deleted, need to keep info about // document status. Also, updating documents when contents change is not // handled. // deleteDocument("00001"); // addDocument(fluoClient, "00003", "ciao world"); // deleteDocument("00003"); // miniHelper.getMiniFluo().waitForObservers(); // printWordCounts(fluoClient); System.out.println("\nStopping Mini ...\n"); } FileUtils.deleteQuietly(miniAccumuloDir); }
From source file:io.apiman.tools.jdbc.ApimanJdbcServer.java
public static void main(String[] args) { try {//from w w w .ja va2s . com File dataDir = new File("target/h2"); String url = "jdbc:h2:tcp://localhost:9092/apiman"; if (dataDir.exists()) { FileUtils.deleteDirectory(dataDir); } dataDir.mkdirs(); Server.createTcpServer("-tcpPassword", "sa", "-baseDir", dataDir.getAbsolutePath(), "-tcpPort", "9092", "-tcpAllowOthers").start(); Class.forName("org.h2.Driver"); try (Connection connection = DriverManager.getConnection(url, "sa", "")) { System.out.println("Connection Established: " + connection.getMetaData().getDatabaseProductName() + "/" + connection.getCatalog()); executeUpdate(connection, "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username))"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')"); executeUpdate(connection, "INSERT INTO users (username, password) VALUES ('ballen', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')"); executeUpdate(connection, "CREATE TABLE roles (rolename varchar(255) NOT NULL, username varchar(255) NOT NULL)"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('user', 'bwayne')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('admin', 'bwayne')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('ckent', 'user')"); executeUpdate(connection, "INSERT INTO roles (rolename, username) VALUES ('ballen', 'user')"); } System.out.println("======================================================"); System.out.println("JDBC (H2) server started successfully."); System.out.println(""); System.out.println(" Data: " + dataDir.getAbsolutePath()); System.out.println(" JDBC URL: " + url); System.out.println(" JDBC User: sa"); System.out.println(" JDBC Password: "); System.out.println( " Authentication Query: SELECT * FROM users u WHERE u.username = ? AND u.password = ?"); System.out.println(" Authorization Query: SELECT r.rolename FROM roles r WHERE r.username = ?"); System.out.println("======================================================"); System.out.println(""); System.out.println(""); System.out.println("Press Enter to stop the JDBC server."); new BufferedReader(new InputStreamReader(System.in)).readLine(); System.out.println("Shutting down the JDBC server..."); Server.shutdownTcpServer("tcp://localhost:9092", "", true, true); System.out.println("Done!"); } catch (Exception e) { e.printStackTrace(); } }